Junior — Middle
Can you explain the structure and components of an HTTP request and response?
sobes.tech AI
Answer from AI
An HTTP request consists of three main parts:
- Request Line — contains the method (GET, POST, etc.), URL, and protocol version.
- Headers — key-value pairs that convey meta-information (e.g., Content-Type, User-Agent).
- Body — optional part that contains data, for example, in POST requests.
An HTTP response also has three parts:
- Status Line — contains the protocol version, status code (e.g., 200), and a textual description (e.g., OK).
- Headers — meta-information about the response (Content-Type, Content-Length, etc.).
- Body — data returned by the server to the client (HTML, JSON, images, etc.).
Example of a request start line:
GET /index.html HTTP/1.1
Example of a response start line:
HTTP/1.1 200 OK