r/eli5_programming • u/Magpie_Reawakened • Oct 07 '26
Question What actually is API?
The moment I think I get it, another definition of it comes in. I was learning Flask APIs used with GET PUT PATCH DELETE . But then I started with JS , it has DOM APIs . And then API is also used when people say companies like ChatGPT , Higgsfield etc provide their APIs.
6
Upvotes
12
u/deadbody408 Oct 07 '26
A way to interact with a thing programmatically
10
u/wiggle_room1337 Oct 07 '26
It's like a UI but no gui. imagine controlling your program with buttons and knobs, but it's just code.
5
u/logical_bit Oct 08 '26 edited Oct 09 '26 •
It's like a telephone. A program calls another program and now they can interact. Some apis may be like a rotary phone with very limited capabilities, while other apis may have the functionality of smartphones and much can be done with them. That's it.
Edit: thank you so much for the award!
1
u/pajoem2000 Oct 09 '26 edited Oct 09 '26
API is just a url, sometimes you can go to it in a browser (take a look at public APIs that dont require keys), but most of the time you call it / go to it via code. The typical language that you use to talk to it (to get data and send data) is JSON (more modern) or XML (older).
The best way I think about an API and how the data moves is think of a marketplace (Amazon, Walmart, Ebay...etc) where you want to sell an item. A marketplace has an API with different endpoints (which are just different sub URLs).
You connect to that API, lets say the endpoint is "API/create", and send JSON using a POST to it, creating a product that then is saved in the marketplace database. Think of the term "posting on my blog", a POST command is a request to save to the database.
Then you can check the product at "API/check" using a GET request, to ask what info the marketplace now has saved about your product. Note: every time you go to a website in your browser you are doing a GET.
You can update (PUT/PATCH) the product adding pictures, bio, inventory count, bullet points, and then you can delete (DELETE) the product when you run out of inventory...etc all from the API.
Now ChatGPT, as you mention, "provides" an API, which is just another way of saying they have an API. ChatGPT has an API that you can connect to, using your keys from your account so they can bill you for usage. Rather than opening a browser to ask the AI a question, you can do it in code.
Why would you do this? Imagine you want an AI bot on your own website, rather than coding your own AI, you create a pop up on your site and let the customer ask the popup a question. Your code copies the question and connects to ChatGPT via the API, asking the same question. Once your code get the response back from ChatGPT it then regurgitates the response to the customer on your website. This makes your site look like it has a sophisticated bot when in reality you have been secretly using ChatGPT. In coding this is called a wrapper as you have wrapped up ChatGPT in your popup code.
3
u/kitsnet Oct 08 '26
API is literally "Application Programming Interface". A way to control one application from another.
2
u/toochtooch Oct 08 '26
API is like a steering wheel to a car. It's a common interface to handle a four-wheeled box. Anywhere in the world you'll see this shape and you'll know what to do. You don't need to understand rack-and-pinion steering, fuel injectors, or hydraulic brake lines. You turn the wheel, press the pedal, and the system executes the heavy lifting underneath. steering wheel sometimes is on the left, sometimes it's on the right, sometimes it has three pedals and a manual transmission, but generally it does the same thing. You get in and you use it to turn the vehicle.
This contract of seeing a steering wheel in a box with pedals is what APIs are. Cars come in different shapes and sizes, just like applications do, but the programming interface part allows both hands to agree on how to use a program and what to expect as a result.
1
u/Technical_Goose_8160 Oct 07 '26
It's an endpoint. You call the IP or URL, send it a msg and it sends you a msg back. When people talk about publishing an API, they want the company to make an address publicly reachable in order to communicate more quickly.
1
u/[deleted] Oct 08 '26
Imagine you write an addition function in JavaScript. Then you write one for multiplication, division, subtraction, exponents and so forth. At that point you basically have a small math API. Just a collection of functions and data structures tailored around one task.
1
u/omniuni Developer Oct 08 '26
An API is basically the agreed upon language that computer programs use to talk to each other. The Flask API uses a common approach (REST) and builds on it.
Slightly more technical, if we agree that if I call a certain function I will get a specific reply, we have created an API.
1
u/Sad-Environment-932 Oct 10 '26
application programming interface.
1
u/Arcanite_Cartel Oct 10 '26
An API is a standardized and consistent way for one piece of software to interact programmatically with another. There's no one size fits all..... many tend to be REST based, some are SOAP based, some graphQL, even a library with a well defined set of functions is an API. There are many different APIs.
1
u/Living_Fig_6386 Oct 14 '26
API = Application Programming Interface.
It's any supported way that one piece of software (web service, library, application, etc.) can use / invoke another piece of software. The term also applies to the documentation that explains the process.
Software very often is written to interact with other software, or calls upon it to do certain things. Your web browser uses features of the operating system to communicate over a network and draw things on the screen. Programming languages some with libraries of common routines, functions, and data structures to do common things like write files, or print things on the display. There are websites that you can request information from by sending a properly formatted request...
The documented way that one piece of software is intended to interact with another is an API - however that might work.
1
u/Agitated_Heat_1719 Oct 08 '26
Contract
Like steering wheel is contract for the car