HTTP Request & HTTP Response
What is HTTP Request?
HTTP Request is a packet of information that is sent by a client to a server. The information sent is in the form of a packet of binary data.
HTTP Request contains the following parts:
Request Line:
Request Line specifies the Method Token (GET, PUT, POST, DELETE ) followed by the Request URI with the HTTP protocol version. The elements are separated by space characters.
Headers could be zero or more:
HTTP Request contains zero or more Request Headers. All the information present between Request Line and Request body are HTTP Request Headers. It allows the client to pass additional information about the request to the server. These fields act as request modifiers. Here below is the list of important Request-header fields that are commonly used based on the requirement:
- Accept-Charset
- Accept-Encoding
- Accept-Language
- Authorization
- Proxy-Authorization
- Range
- User-Agent
Request Body:
Request body contains additional information which is required by the server to process request properly. In the case of Rest APIs, it is usually sent in the form of JSON/XML format.
Request Method
The request method indicates the method to be performed on the resource identified by the given Request-URI.
GET: The GET method is used to retrieve the information from the server. It doesn’t support any modification of the data.
HEAD: The HEAD method is identical to that of a GET request, but without the response body. It retrieves the status line and header section.
POST: The POST method is used to send data to the server to create a new resource.
PUT: The PUT method is used to send data to a server to update an existing resource
DELETE: The DELETE method deletes the specified resource.
CONNECT: The CONNECT method establishes a tunnel to the server identified by the target resource.
OPTIONS: The OPTIONS method is used to describe the communication options for the target resource.
TRACE: The TRACE method performs a message loop-back test along the path to the target resource.
PATCH: The PATCH method is used to apply partial modifications to a resource.
What is HTTP Response?
HTTP Response is a packet of information that is sent by a server to a client. It contains the information requested by the Client. It is also sent is in the form of a packet of binary data.
HTTP Response contains the following parts:
Status Line:
Status Line is divided into three parts:
- HTTP Protocol Version
- Status Code
- Status Message
Response Header:
HTTP Response also contains zero or more Response Headers. All the information present between Status-Line and Response body are HTTP Request Headers. It allows the server to pass additional information about the response which cannot be placed in the Status-Line. Here below is the list of important Response-header fields that are commonly used based on the requirement:
- Accept-Ranges
- Location
- Proxy-Authenticate
- Retry-After
- Server
Response Body:
It contains the data which is requested by the client. In the case of Rest APIs, it is usually sent in the form of JSON/XML format.
Status Code
The Status-Code element is a 3-digit integer where the first digit of the Status-Code defines the class of response and the last two digits do not have any categorization role. There are 5 values for the first digit:
1. 1xx: Informational
It means the request was received and the process is continuing.
2. 2xx: Success
It means the action was successfully received, understood, and accepted.
3. 3xx: Redirection
It means further action must be taken in order to complete the request.
4. 4xx: Client Error
It means the request contains incorrect syntax or cannot be fulfilled.
5. 5xx: Server Error
It means the server failed to fulfill an apparently valid request.