API requests

An API request is a way for one software application to communicate with another software application to access or exchange data or functionality.
To make an API request, a client application sends a request to the receiving application (referred to as server application) using a specific URL, which includes:
  • A request method – such as GET, POST, PUT, DELETE
  • Any necessary parameters or data
The server application then processes the request and sends a response back to the client application, usually in the form of structured data – in formats such as JSON or XML.

APIs are widely used

API requests can be used for a wide range of purposes, including retrieving data from a remote server, submitting data to a remote server for processing, updating data on a remote server, and triggering specific actions or events on a remote server.
API requests are widely used in web and mobile application development, as well as in the integration of various software systems.
In fact, every time you visit a website you are effectively sending a request!

Example

Let's say you are really into cats, and you want to get a new cat-related fact every day.
Well, there's an API for that! Specifically, the catfact.ninja API.
And with this short SplootCode program you can easily access it and get all the cat facts you want, right in SplootCode.
So what the program above is doing is sending a request to the catfact.ninja API, and the catfact.ninja API is sending back a response.
SplootCode is then grabbing this response – that comes in formatted as a JSON file (don't worry about this for now) – and transforming it into normal text.
Here's what the raw JSON file looks like
{
"fact": "Tigers are excellent swimer and do not avoid water",
"length": 41
}
This response contains more data as well – that is the length of the fact.
To learn more about what this means (and why it's cool) read on to API responses to learn more.