The Structure of a Request
Every HTTP request sent by a browser is structured as text (in HTTP/1.1) containing three parts: a request line, headers, and an optional body payload.
HTTP Snippet
http
POST /api/users HTTP/1.1
Host: example.com
User-Agent: Mozilla/5.0
Content-Type: application/json
Content-Length: 27
{"name": "Alice", "role": 1}Request Methods
The request line specifies the method indicating the action to perform:
- GET: Retrieve a resource without side effects.
- POST: Submit data to create a resource.
- PUT: Replace an existing resource.
- DELETE: Remove a resource.
Request Headers
Headers pass metadata about the client and request context. Examples include "Host" (the destination domain), "User-Agent" (browser details), and "Accept-Encoding" (supported compression like gzip or brotli).
