Junior — Middle
What are the components of an HTTP request?
sobes.tech AI
Answer from AI
An HTTP request consists of several 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, authorization, cookies).
-
Body — optional part used to transmit data (e.g., in POST requests).
Example of a request line and headers:
POST /api/users HTTP/1.1
Host: example.com
Content-Type: application/json
Authorization: Bearer token
{"name":"John"}
Here:
POST— method/api/users— pathHTTP/1.1— protocol version- Headers convey additional information
- Body contains JSON data of the user.