Sobes.tech
Middle

Tell me about the structure of an HTTP request and response.

sobes.tech AI

Answer from AI

An HTTP request consists of three main parts:

  1. Request Line — contains the method (GET, POST, etc.), the resource URI, and the protocol version.

  2. Headers — key-value pairs that convey meta-information, such as content type, cookies, authorization.

  3. Body — optional part that contains data, for example, in POST requests.

Example of a request:

POST /api/users HTTP/1.1
Host: example.com
Content-Type: application/json
Content-Length: 48

{"name":"Ivan","email":"ivan@example.com"}

An HTTP response also consists of three parts:

  1. Status Line — protocol version, status code (e.g., 200 OK).

  2. Headers — meta-information about the response, such as content type, length.

  3. Body — data returned by the server, such as HTML, JSON.

Example of a response:

HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 27

{"id":123,"status":"ok"}
Tell me about the structure of an HTTP request and… - sobes.tech