Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors

HTTP Protocol : Request and Response

The Hypertext Transfer Protocol (HTTP) is the foundation of communication on the web. It allows clients (like web browsers) to request resources from servers (like websites) and receive responses.

HTTP Request

1. Method

The client initiates a request by specifying an HTTP method.

Common methods include:

  • GET: Retrieve data from the server.
  • POST: Submit data to be processed to a specified resource.
  • PUT: Update a resource on the server.
  • DELETE: Request the removal of a resource.

2. URI (Uniform Resource Identifier)

The client specifies the resource it is requesting or acting upon using a URI.

This is often in the form of a URL (Uniform Resource Locator).

3. HTTP Version

The client indicates the version of the HTTP protocol it is using.

4. Headers

The client can include additional information in the form of headers. Headers can convey details about the request, such as the type of content the client can accept, authentication information, and more.

5. Body (Optional)

Some requests, like POST or PUT, may include a message body where data is sent to the server.

Example of an HTTP request

GET /example/resource HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64)

HTTP Response

1. Status Line

The server responds with a status line that includes:

  • The HTTP version.
  • A status code indicating the result of the request.
  • A corresponding status message.

2. Headers

Similar to the request, the server includes headers in the response. Headers provide additional information about the response, such as content type, length, server information, etc.

3. Body (Optional)

The server may include a message body containing the requested data or additional information.

Example of an HTTP response

HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 1234

<!DOCTYPE html>
<html>
  <head>
    <title>Example Page</title>
  </head>
  <body>
    <p>This is the content of the page.</p>
  </body>
</html>

In this example, the status code “200 OK” indicates that the request was successful, and the server includes an HTML document in the response body.