HTTP Basics, HTTP Response, and Request Object

HTTP Basics, HTTP Response, and Request Object


HyperText Transfer Protocol (HTTPS) is an application-layer protocol designed to communicate between clients and servers. It is also a stateless protocol, that does not keep the state/data between two requests.



Flow of a HTTP call


Flow of a HTTP call

a. Open a TCP connection.

b. Client sends an HTTP Request (How the request object looks is discussed below).

c. Server receives the request. Process it, and send back the response.

d. Client receives the response and process the response.


HTTP Request Object

There are three main components of HTTP Request:

1. HTTP Verb/Actions


Verb is the action that we want to perform at the server. The most common HTTP verb used is Get; when we want some web pages to load or to get any resource we use the Get. Next, we have Post which is used to create or insert a new resource. When we want to insert a new record in the server we use the Post request. We have Put request which will used to modify a record. Finally, we have Delete request that will be used to delete a record. These are most commonly used verbs. However, there are many others too.

2. Headers


Headersare the name value pairs about the metadata about the request. There are many headers, but the most common are Content-Type that tells what type of content (such as JSON) is present in the body, Content-Length that tells the server what length of the content is available in the body.

3. Content


This contains the content of the request. It can be JSON, HTML, CSS , etc. This contains the actual data which is required by the server to process the request. For example, the data to be inserted in the database.


HTTP Response Object

There are three main components of HTTP Response:

1. Status Code


When a client makes a call to the request, it needs to know the status of the request. To know the status of the request, it will check the status code in the response object. The following are the status code values: 200-299 (Success), 100-199 (information), 300-399 (redirection), 400-499 (Client errors), 500-599 (Server errors).

2. Headers


This is same as Request Object's header.

3. Content


This is same as Request Object's content.