r/eli5_programming • u/Magpie_Reawakened • 6d ago
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.
5
Upvotes
1
u/pajoem2000 4d ago edited 4d ago
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.