-2

I'm new to APIs. Conceptually, I understand what an API is, but I get confused when it comes to the some of the technical details.

All of the tutorials I've read talk about URLs and endpoints, and they describe them as being the paths/addresses through which APIs can be accessed. This part is very clear; no confusion here.

However, what I don't understand is how APIs are called. In other words, in a real-world scenario, people don't actually type in a URL in some input box to call APIs, so I assume the calling is done behind the scenes, by some program, and in response to some trigger event? If my assumption is true, is it also true that when using a client like Postman to test APIs, you are basically emulating the behavior of said program?

Lastly, where are APIs typically stored?

  • It's not clear to me what you are asking: "where are APIs typically stored?" Can you make this clearer? or describe the sort of thing you would be able to do if you knew the answer? – VoiceOfUnreason Jul 18 '19 at 1:30
  • Sure. What I mean is, when an API is implemented/deployed, where does the code reside? (and thanks for your feedback, btw) – entropy1 Jul 18 '19 at 1:46
  • I feel like with all the buzzwords floating around today, if we're not careful, the next generation of programmers will not know that the term API means. So just to get the concepts straight: API is a more general term, and it doesn't have to be related to the Web or URLs at all - see this. A web API is one kind of API. – Filip Milovanović Jul 18 '19 at 3:17
4

However, what I don't understand is how APIs are called. In other words, in a real-world scenario, people don't actually type in a URL in some input box to call APIs, so I assume the calling is done behind the scenes, by some program, and in response to some trigger event?

For a web-api, there will typically be two parts.

One part of the program will be a library, that knows how to construct HTTP requests out of some provided hints, how to address that request so that it can be delivered to another machine on the network, how to listen to messages from the network and reconstruct the HTTP responses from them, and how to parse the response to extract useful information from it.

Very broadly, these are called http client libraries. A "web browser", for example, will have some sort of http client library, as well as a bunch of code for rendering the results, processing actions by the user, keeping track of bookmarks and preferences, and so on.

The second part of the program will know the API, which is to say the semantics of the messages that should be sent and read, without necessarily knowing how to create the messages. So it will "know" what URI(s) to use, or how to create them from a template and a list of parameters, and what information should go in the body of the message, and which links to look for in the response.

If my assumption is true, is it also true that when using a client like Postman to test APIs, you are basically emulating the behavior of said program?

Right - using a http client will allow you the human being to tell the client to interact with the API on your behalf (you being a replacement for the "second part" of the program).

when an API is implemented/deployed, where does the code reside?

Usually, the code that implements the API is running within the web server process itself. It looks like the client case, but mirrored -- the generic http server framework will call into the library that implements the interface.

| improve this answer | |
1

However, what I don't understand is how APIs are called. You are correct that APIs are called behind the scenes. This requires the use of client capabilities such as XMLHttpRequest.

For a browser, javascript is used to make such a request to the API endpoint. The browser frontend application will need to be programmed to handle the response and change the view accordingly.

is it also true that when using a client like Postman to test APIs, you are basically emulating the behavior of said program?

When using postman, you are doing the same thing, just without some browser specific features (since postman does not first retrieve a webpage, then make the request, it just sends the request directly).

Lastly, where are APIs typically stored?

APIs are usually stored in the code since the endpoint must be called to use it. Documentation for APIs is usually documented in more mature projects, while you might have to dig through the code to find the API definitions for smaller projects.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.