Monday, February 4, 2019

API Testing 03: Client Server Architecture, HTTP Protocol and REST APIs Design

Client - Server Model:

In Client Server Architecture the machine that requests for some data or the machine that consumes the data is called Client and the machine the accepts the client's requests and provides the required data as response is called Server.

The client and server connected with each other with Internet (world wide web), and they use common medium and common language to communicate each other. The medium they use is HTTP Protocol and the language use JSON or XML data formats.

Which means the client will be sending HTTP Request to server in JSON or XML format, and server understands the request and sends HTTP Response JSON or XML format. Below is the sample image showing the client server architecture.




HTTP Protocol:

Hyper Text Transfer Protocol is mostly used for transferring the files (HTML files, Images, Videos and etc.) over the internet. REST APIs or RESTful Web Services makes use of the basic features of HTTP like Connection less, Media Independent and Stateless and become powerful web services.

The request sent from client to server using HTTP Protocol is called HTTP Request and the response that a server sends to a client is called HTTP Response.

HTTP has different methods to perform different operations on the REST APIs, the mostly used HTTP methods are called CRUD operations which stands for Create, Read, Update and Delete operations.

  • Create - POST Request : This is used for creating a new resource on the server side.
  • Read - GET Request: This is used for reading the resources on server side.
  • Update - UPDATE Request: This is used for updating the resources on the server side.
  • Delete - DELETE Request: To delete the resources from server

HTTP Request Structure:

HTTP Request is a packet of information that a client machine sends to server machine for required data. HTTP Request consists of:
  1. Request Line
  2. Zero or more headers
  3. An empty line
  4. An optional body
1. Request Line: It consists of Request method (GET/POST/PUT), Request URI and HTTP Protocol version

Example:
Get http://www.w3.org/pub/WWW/TheProject.html HTTP/1.1

2. Headers: Headers can be zero or more. Used for language specification, content-type, proxy specification, authorization specification and etc:

Example:
Accept-Language: en-us
Content-Type: application/JSON

3. Empty line: Indicating end of header fields

4. Optional Body: Used for sending additional information to server in the form JSON or XML.

HTTP Response Structure:

HTTP Response is result or response from the server machine to client machine for the request it sent. It consists of:
  1. Status Line
  2. Zero or more headers
  3. Empty Line
  4. Option body
1. Status Line: It consists of HTTP Version, Status Code and Reason Phrase

2. Header: It contains, Content-Type, Server and etc specifications.

Example:
Server: Apache/2.2.14 (Win32)
Last-Modified: Wed, 08 Feb 2019 16:47:36 IST
Content-Length: 88
Content-Type: text/html

HTTP Status Codes: Some of the HTTP Status codes and their description below
  • 200 - OK
  • 201 - Created
  • 202 - Accepted
  • 204 - No content
  • 400 - Bad Request
  • 401 - Unauthorized
  • 404 - Not Found
  • 500 - Internal Server Error
  • 501 - Not Implemented

REST APIs Design:

When we say RESTful Web Service, it means two REST APIs of client and server are communicating with each other over internet. Client and Server will have different APIs for different purposes. When invoked a REST API from client machine in any communication corresponding REST API will respond on the server machine.

In Web Service, client and server are nothing but applications. Lets understand this with an example:


If we are booking a flight ticket on www.goibibo.com application, we will be entering source, destination and date of travel and clicking on the search button. Then a API in the back-end takes all the user information in JSON/XML format and it will sends out a HTTP Request to different flight service provider servers like Air India, Air Asia, Indigo, Jet Airways and etc. Now another API on server side decodes the HTTP Request, processes it and sends out HTTP response in JSON/XML format based on the data received client API will displays it on GUI of the application. All this communication happens in no time in the back-end. This is how REST APIs communicate each other.

In the upcoming tutorials we will see in detail about HTTP Request, HTTP Response and HTTP Methods.

#HappyLearning #HappyTesting

No comments:

Post a Comment

Katalon 08: Integration of HP ALM with Katalon Studio

In this post, this post we discuss about integration of  HP ALM with Katalon Studio. If we can integrate HP ALM with Katalon we can update ...