Hack Frontend Community

How HTTP Works and What an HTTP Request Consists Of

HTTP (HyperText Transfer Protocol) is data transfer protocol used for exchanging information between client (e.g., web browser) and server over Internet. HTTP is foundation of World Wide Web and is used for requesting and transferring data such as HTML pages, images, videos and other resources.

How Does HTTP Work?

HTTP works on client-server principle. When user enters URL in browser or clicks link, browser sends HTTP request to server, which processes request and sends back HTTP response with requested data.

HTTP workflow looks like this:

  1. Client (e.g., web browser) sends HTTP request to server.
  2. Server receives request, processes it and sends HTTP response with result.
  3. Response can contain requested data, e.g., HTML page, image or text.

What Does HTTP Request Consist Of?

HTTP request consists of several parts.

  1. HTTP Method: Method determines what action server should perform with requested resource. Most common HTTP methods:

    • GET — requests resource (e.g., page).
    • POST — sends data to server for processing (e.g., form submission).
    • PUT — updates resource on server.
    • DELETE — deletes resource from server.
    • HEAD — requests only resource headers, without body.
  2. URL (Uniform Resource Locator): This is address of resource being requested. Includes protocol (e.g., http://), domain, path and query parameters.

  3. HTTP Version: Indicates HTTP protocol version used by client for request. In most cases HTTP/1.1 or HTTP/2 version is used.

  4. Request Headers: Headers contain metadata about request. These can be data about content type, language, cookies, authorization and other parameters that may be useful for server to process request.

    Header examples:

    • Content-Type — content type (e.g., text/html, application/json).
    • User-Agent — information about client browser or device.
    • Authorization — authentication data.
    • Accept — indicates which data types client is ready to accept from server.
  5. Request Body: Request body is used in methods such as POST, PUT or PATCH to send data to server. Body can contain information such as forms or JSON data.