
As introduced in previous articles, the data format in the API usually uses two main types: JSON (JavaScript Object Notation) and XML (Extensible Markup Language). Today, I will talk more about each type of format.
Table of Contents
JSON
Nowadays, JSON data format is used a lot in Restful API. It is built from Javascript, which is widely used language, compatible with both front-end and back-end of both web app and web service. JSON is a simple format with two components: keys and values.
– Key represents the properties of Object
– Value represents the value of each Key

In the above example, keys are on the left, values are on the right.

There are many cases, 1 Key will have a Value as a sequence of key + value. For example picture:

XML
In JSON use { } and [ ] to mark data. XML is similar to HMTL, uses tags for markup and is called nodes.
Take the example above but write it in xml, it would look like this:

Data format in HTTP
Back to previous articles, the header has the function to save information that the user does not know, including a component that determines the format of the data: Content-Type
When the client sends the Content-Type in the request’s header, it is telling the server that the data in the request’s body is formatted that way. When the client wants to send JSON it will set the Content-Type as “application/json”.
When starting to receive the request, the server will check the first Content-Type and so it knows how to read the data in the body. Conversely, when the server sends back a response to the client, it also sends back a Content-Type to tell the client how to read the body of the response.

Sometimes the client can only read one type of format, for example, JSON but the server returns XML, the client will get an error. Therefore, another component in the header, Accept, will help the client deal with the problem by telling the server what type it can read. Example: Accept : “application/json” .
Based on 2 components Content-Type and Accept, client and server can understand and work correctly.
Thank you for reading.
To see more articles about API testing , please go this link