Junior — Middle
What components does an HTTP protocol request consist of?
sobes.tech AI
Answer from AI
An HTTP request consists of several main components:
-
Request Line — contains the method (GET, POST, etc.), URI (resource address), and HTTP protocol version.
-
Headers — a set of "key: value" pairs that convey additional information about the request, such as content type, language, cookies, etc.
-
Body — an optional part that contains data sent to the server (for example, in POST requests).
Example request:
POST /api/user HTTP/1.1
Host: example.com
Content-Type: application/json
Content-Length: 48
{"name":"Ivan","email":"ivan@example.com"}
In Go, the standard library net/http provides the http.Request structure, which contains all these components for convenient handling of HTTP requests.