According to the previous considerations about communication, an API is a set of rules that state
how components / computers / applications communicate with one another. These rules are usually
defined in an API specification.
In general, this process of API working can look like this:
- A client component initiates an API call (a request) - to retrieve a resource, an
information
(with the usage of GET verb/method). This request is processed from a client application to
a web server.
- The server sends a response to the API with the required data
- The API then transfer the data to initial requesting component/application
There are also available others verbs/methods: POST to add new objects, PUT, PATCH to update them,
and DELETE to remove them.
With reference to REST API we say that it enables the transfer of representation of a resource’s
state.
The following figures show in an illustrative way the example of communication within REST
API:
Figure 1
Figure2
What’s also interesting, API uses response codes. They notify clients about the status of the
request, if it succeed, if it failed and what kind of error occurred. Most client applications
checks for response code ad act accordingly.
There are five response code groups and each group contain its status code. Probably, the most
popular from user perspective is the response code from client error group, with the status 404 -
page not found. We sometimes get it with some strange or funny pictures, when we try to go to some
website which for example has been removed.
When it comes to language that is used to communication within API, XML should be mentioned as
at the one that has been used very often, but in today’s solutions dominates JSON.
Here we have some simple example of JSON file that contains some users data:
Figure3