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 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

#HappyLearning #HappyTesting

No comments:

Post a Comment

Java Program 5: How to reverse given string and each word of it?

Let us understand the problem with an example, suppose "Learn Core Java" is the given string then the expected output should be &...