Monday, July 1, 2019

API Testing 05: Client Server Architecture and HTTP Protocol

Client - Server Model:

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

The client and server connected with each other with Internet (world wide web), and they uses common medium and common language to communicate with 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, server understands the request and sends HTTP Response in 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 protocol like connection less, media independent and stateless and became 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 Methods:

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
Thanks for reading. Hope this post gave you basic understanding of client-server architecture and HTTP Protocol.

#HappyLearning #HappyTesting

No comments:

Post a Comment

How do you identify broken links in Selenium Automation?

When we are asked to identify the broken links in the application, what we do? Collecting all the links on the page to a list and looping t...