API testing – What is API Protocol ?

API testing

In the previous post, I explained the role of API for client and server, this article will talk about API Protocol – the way how those two guys talk to each other (roughly called 2 computers).

What is API protocol ?

Suppose: There are 2 people A and B talking to each other on the phone, if person A asks a question and then stays silent, person B will know that person A is waiting for an answer and it is person B’s turn to speak. The two computers also communicate politely and are described with the term “Protocol”.

API protocol are the accepted rules for two computers to talk to.

However, this rule is much stricter than human-to-human communication. The computer will not be smart to be able to recognize that two sentences “A is husband B” or “B is wife A” have the same meaning. For two computers to communicate effectively, the server must know exactly how the client arranges the message it sends.

We have heard of Protocols for different purposes, such as Mail with POP or IMAP, messages with XMPP, Device connection: Bluetooth. In the web, the main Protocol is HTTP – HyperText Transfer Protocol, and it is the protocol used for APIs.

How does HTTP works ?

The life of HTTP revolves around a vicious cycle: Request and Response. The client sends the request, the server sends back a response as to whether the server can do what the client wants or not. And the API is built on two main components: Request and Response. First, we must understand the structure of each component.

Request

A standard request requires 4 things:

1. URL

2. Method

3. Headers

4. Body

OK, now look at each of them one by one.

  • An URL is a unique address for something (using a noun), be it a web page, image, or video. The API extends the original idea of ​​URLs to other things, e.g. customers, products. And so the client easily tells the server what it wants, these are also known collectively as “resources”.
  • Method: is the action the client wants to act on “resources”, and it is usually a verb. There are four commonly used methods:
    GET: Ask the server to return resources: Imagine the scene on fb, swiping new feeds.
    POST: Ask the server to create a new resource. For example, register for a ride at bike app.
    PUT: Ask the server to edit / add resources already on the system. Example: Edit 1 post on fb.
    DELETE: Ask the server to delete a resource. This probably doesn’t need an example.
  • Headers: where contains the necessary information of a request but end-users do not know its existence. For example, the length of the request body, the time it took to send the request, the type of device in use, the type of response format that the client can read…
  • Body: where the client will fill in the information. Suppose you order a pizza, the information in the body will be: Type of pizza, size, quantity ordered.

Response

After receiving a request from the client, the server will process that request and send a response back to the client. The structure of a response is quite similar to the request part, but the Status code will replace the URL and Method. In a nutshell, it has a 3-part structure:

1. Status code

2. Headers

3. Body

Status codes are 3-digit numbers with only 1 meaning. Surely you are no longer strange to the Error “404 Not Found” or “503 Service Unavailable”. Full list is available here.

Headers and Body are similar to request.

Thank you for reading.

To see more articles about API testing , please go this link

Leave a Reply

Your email address will not be published. Required fields are marked *

API testing

Test runner – API testing

Test runner – According to the previous post, you already know how to create simple tests for each API, but a project has too many APIs and too many different tasks, each task is a collection of several APIs how must be solved. Along with that is the management method that you think is applicable […]

API testing

How to test API

After reading “test API with Postman” series, you should be able to grasp the basic knowledge of the API and the functions Postman provides. But how to arrange tests and write Testcases for API still seems not very clear, so today I will write a post about how to test API properly. Reminder of knowledge […]

API testing

API testing – API documentation

Postman, in addition to providing an API testing tool, also helps us to make API documentation extremely professional and easy. This API document can be shared by both the team and the client. Usually, the API is usually written by Dev on google sheets, but at a certain stage of development, the dev will be […]