What is API?

476 viewsEngineeringOther

What is exactly API and why we call it like that? I am learning web development, and always come across APIs. I would love to learn it through an analogy.

In: Engineering

32 Answers

Anonymous 0 Comments

Lots of folks offering the menu analogy, which is helpful but I think has limitations.

Another way to think of an API is like the contract a service publishes. For example
“if you send a GET request to /users, I will return a list of users” 
“if you want to get the data about a user with id 12345, send a GET request to /users/12345. If user 12345 doesn’t exist, you will receive a 404 not found error”
“If you want to delete user 12345 send a DELETE request to /users/12345”

Like others pointed out, one value here is that you don’t need to know what’s going on under the hood for this to work. It also means that the service maintainer can change how they accomplish the tasks as long as they keep the API the same. This is really powerful – as a maintainer, I can rewrite parts of the code to make it faster, or change the database I store things in, or switch operating systems, etc. As long as I keep the API the same, my users don’t care*

*ok, if I made it a lot slower they’d care

often when people refer to an API, they’re talking about an HTTP API, so you’re making HTTP requests to an HTTP server somewhere, and that server implements the API. That’s not the only kind of API, though – APIs can also refer to system calls in an operating system, for example.

You are viewing 1 out of 32 answers, click here to view all answers.