Junior — Middle
Can you name the main components that make up the structure of an HTTP request?
sobes.tech AI
Answer from AI
Main components of an HTTP request:
- Method (HTTP Method) — indicates the action, such as GET, POST, PUT, DELETE.
- URL (Uniform Resource Locator) — the address of the resource being requested.
- Headers — request metadata, such as
Content-Type,Authorization. - Body — data sent to the server (usually in POST, PUT requests).
- Protocol version — for example, HTTP/1.1 or HTTP/2.
Example of a simple HTTP request:
POST /api/users HTTP/1.1
Host: example.com
Content-Type: application/json
Authorization: Bearer token
{"name":"John", "age":30}
Here, the method is POST, the URL is /api/users, headers include Host, Content-Type, Authorization, and the body contains JSON data of the user.