An HTTP request is how a client (e.g., a web browser or an app) communicates with a server over the web. Here's a breakdown of the basic components:
HTTP methods define the type of action to be performed:
The URL specifies the endpoint on the server the request is directed to:
https://api.example.com/users/123
https://
(HTTP or HTTPS)api.example.com
(server)/users/123
(resource location)HTTP headers provide metadata about the request or the response:
The body contains data to be sent to the server, typically used in POST, PUT, or PATCH requests. The format is often JSON but can also be XML, form data, etc.
Example (JSON body for creating a user):
json
Copy code
{
"name": "John Doe",
"email": "[email protected]"
}
Query parameters are optional pieces of data added to the URL, often used to filter or modify the request: