This is the first chapter of REST API Testing with Rest-Assured series. Before jumping in to the code, it is necessary to understand Basics of Client Server Architecture and HTTP Protocol.
Client Server Architecture
To understand client server architecture let us take a small example. Let us say that we need to get the weather data for my city today. To do this I will need to ask someone who knows about the weather conditions of my city. Assuming that computers are not yet available, we would typically look at the day’s newspaper or may be listen to the radio.
In this process, there are two distinct participants. First one is you, who wants the information about the weather. The second one is the Radio or Newspaper who provides the information. If we were to name these two participants we have
- Consumer who wants to consume a specific information. Also, called as Client in Client-Server context.
- Provider who provides the information. Also, called as Server in Client-Server context.
In the age of Computers, a client and a server are two computers separated by miles but connected by Web (Internet). However, important point to note here is that it is not necessary that Client and a Server should be miles apart, it could be that Client and Server programs are running as two processes on the same computer.
For understanding the Client-Server architecture, we would assume that Client and Server are separated located in different geographies and are connected via Web. Let’s try to visualize this using a small diagram:
HTTP Protocol between Client and Server
Further discussing the above example, we would read a newspaper or listen to the radio to get the weather updates. Newspaper and Radio use your local language and you will be able to understand what is written in the paper or spoken on the Radio. However, for the Clients and Servers on the Web we have to come up with two things
- A medium for communication, specifically a protocol for two systems to interact. Also called HTTP communication protocol
- A protocol to ask for the required details from the server. This could be in any form of formatted data. Most commonly used formats are XML and Json.
- Server responds by sending a Response in any form of formatted data, here also it could be XML or JSON.
To Summarize: A Client and a Server establishes a connection using HTTP protocol. Once the connection is established, Client sends across the request to the Server in the form of XML or JSON which both entities (Client and Server) understand. After understanding the request Server responds with appropriate data by sending back a Response.
To further understand this discussion, lets elaborate on the example of Weather details that we had talked about earlier. If we want to know about the Weather details of a place, we must tell the name of the Place for the Server to tell us the Weather details of that place.
When you Request for the weather details, you specify the place name in the Request.
In turn, the Server send the Response back. This response contains the actual Temperature of the city.
Here is a small step by step diagram to illustrate this process.