What is it?
HTTP is a request response protocol where a client like a web browser sends a request to a server, which then sends back with a response message.Communication between the client and the server is built on a top of a transport layer protocols like TCP.
Structure
The HTML structure is built up by two parts:
- Request Message:
- Request Line: Contains the HTTP method (e.g., GET, POST, PUT, DELETE), the requested resource's URL, and the HTTP protocol version (e.g., HTTP/1.1).
- Headers: Provide additional information about the request, such as the Host and Content-Type.
- Body: An optional field that can contain data to be sent to the server, often in JSON format, such as for a POST request.
- Response Message:
- Status Line: Contains the HTTP protocol version, a status code (e.g., 200 OK, 404 Not Found), and a status message.
- Headers: Provide information about the response, such as Content-Type.
- Body: The actual content requested by the client (e.g., an HTML file, image, or video).
Operation
How HTTP operates:
- Client Initiates: The client (e.g., a web browser) sends an HTTP request to a server to get a resource.
- Server Processes: The server receives the request, processes it based on the method, and prepares a response.
- Server Responds: The server sends an HTTP response back to the client. The response includes a status code indicating success or failure and the requested content, if any.
- Client Renders: The client receives the response and processes it, such as by rendering the HTML page for the user to see.
- Statelessness: HTTP is a stateless protocol, meaning the server does not retain any memory of past requests from the client. Each request is treated as a new, independent transaction, though cookies can be used to maintain state between requests.
- Intermediate Elements: Network elements like proxies and caches can sit between the client and server. Caches can store copies of responses to deliver content faster and reduce traffic, while proxies can handle tasks like authentication, logging, and filtering.
Request methods
HTTP defines a set of request methods to indicate the purpose of the request and what is expected if the request is successful, Such as: