What is API?

API is an acronym for Application Programming Interface. An API is a tool that allows applications to communicate with each other. 

The API operating principle is very simple. An application sends data (known as a request) to a server. The server processes this information and sends back a response. The application then interprets that data and presents it in a readable way.

The response usually comes in JSON format. JSON is an open standard data format that is lightweight and human-readable. It is widely supported in many programming languages.

The big advantage of an API is that developers don't need to know how a server processes this information, which simplifies their work. And also due to this benefit, companies can safely provide their data and functionality to third parties.

APIs are extremely popular. All the most used applications like Facebook, Amazon, and many others apply it.

What is REST?

The API usage growth in all market segments causes the necessity of protocols, standards, and rules that would facilitate to standardize data exchange through the API. The most widespread decision to resolve this issue has become REST.

REST (Representational State Transfer) is a set of web API architecture principles, or constraints, (not a protocol or a standard), that dictate how web service applications communicate over the internet. For this purpose, REST API (also known as a RESTful API) uses the HTTP protocol between client and host server at a predefined set of URLs.

REST API request and response structure

Request:

  • Method (HTTP verbs: GET, PUT, POST, DELETE, etc.)

  • URL (resource and parameters)

  • Headers (meta-data of the request)

  • Body (the content of the request)

Response:

  • Status code

  • Headers (meta-data of the response)

  • Body (the content of the response)

HTTP verbs

The most common HTTP methods are:

  • GET: The get method is used to read (retrieve) data on the server.

  • POST: The post method is used to create data.

  • PUT: The patch method is used to update data.

  • DELETE: The delete method is used to delete data.

URL structure

  • Host name defines the address of the server providing the data

  • Base path defines the API product name, which is typically associated with some business entity, as well as its version

  • Resource name defines the specific API resource, which further details and clarifies possible API request options

  • Query parameters can be used to send supplementary request information, e.g. for filtering, sorting or other actions.

Response codes

HTTP status codes are three-digit codes delivered in the HTTP header. They indicate whether a specific HTTP request has been successfully completed. They also help to identify the cause of the problem when a resource does not load properly.

These codes are grouped into five classes:

  1. Informational responses (100–199)

  2. Successful responses (200–299)

  3. Redirection messages (300–399)

  4. Client error responses (400–499)

  5. Server error responses (500–599)