Junior — Middle
Can you explain what parts the HTTP protocol consists of?
sobes.tech AI
Answer from AI
The HTTP protocol consists of several key parts:
- Request line — contains the method (GET, POST, PUT, etc.), URL, and protocol version.
- Headers — key-value pairs that convey meta-information, such as content type, cookies, authorization.
- Body — optional part, contains request or response data, such as JSON, HTML, or files.
Similarly, in the response:
- Status line with response code and message (e.g., 200 OK).
- Response headers.
- Response body with content.
Example request:
GET /index.html HTTP/1.1
Host: example.com
Accept: text/html
Example response:
HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 1256
<html>...</html>