HTTP Request for beginners

Susan Lozano
2 min readApr 1, 2022

--

HTTP (Hypertext Transfer Protocol) is the foundation of data communication for the World Wide Web. It is a request-response protocol, which means a client (such as a web browser) sends a request to a server, and the server sends back a response.

An HTTP Request is a message sent by the client to the server to request specific information or resources. The request typically includes the following parts:

  1. Request Line: The first line of the request, which includes the method, the requested resource, and the HTTP version. For example, “GET /index.html HTTP/1.1”
  2. Headers: Additional information about the request, such as the client’s IP address, the type of browser being used, and the types of content accepted by the client. Headers are separated by a newline, and each header is in the form of “Header-Name: value”.
  3. Message Body: The content of the request. This is optional and is only used when the request method is POST or PUT.

The most common request method is GET, which is used to retrieve information from the server. For example, when you enter a URL in your web browser and press enter, the browser sends a GET request to the server to retrieve the webpage.

Another common request method is POST, which is used to submit data to the server. For example, when you fill out a form on a webpage and click the submit button, the browser sends a POST request to the server with the form data in the message body.

PUT and DELETE are also request methods that are used less frequently, PUT is used to update a resource on the server, and DELETE is used to delete a resource on the server.

A sample of an HTTP Request :

GET /index.html HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:122.0) Gecko/20100101 Firefox/122.0
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Upgrade-Insecure-Requests: 1

In this example, the request is a GET request for the index.html resource on the www.example.com server. The headers include information about the client’s browser, the preferred languages, and the types of content accepted by the client.

The response from the server to an HTTP request would have 3 parts:

  1. Status line: includes the HTTP version, status code, and a reason phrase, for example, “HTTP/1.1 200 OK”
  2. Headers: Additional information about the response, such as the content type, content-length, and date.
  3. Message Body: The content of the response. This is optional and is only present if the response has a body.

In conclusion, HTTP Request is a message sent by the client to the server to request specific information or resources. The request typically includes the request line, headers, and message body. The most common request method is GET, which is used to retrieve information from the server. Other common methods include POST, PUT, and DELETE. Understanding how HTTP requests work is essential for web development and understanding how the web works.

See you in another article! Don’t forget to clap and follow.

--

--