HTTP (Hypertext Transfer Protocol) is the foundational protocol used for transferring data on the World Wide Web. It defines the rules and conventions for how clients (such as web browsers) and servers communicate. HTTP operates in a client-server model where the client requests data and the server responds.
Client-Server Communication: HTTP follows a request-response model. The client (typically a web browser) sends an HTTP request to a web server for resources (such as web pages, images, or files). The server processes the request and sends back an HTTP response containing the requested resource or an error message.
Stateless Protocol: HTTP is stateless, meaning each request from the client to the server is independent and the server does not store any information about previous requests. After each transaction, the server forgets the client's request. This makes HTTP lightweight and scalable, but it also means that more sophisticated mechanisms (like cookies or sessions) are needed for maintaining state across requests.
An HTTP request is made by a client to a server to request resources, like a webpage or an image. The request includes several parts:
Request Line: Contains the HTTP method, the requested resource, and the HTTP version.
GET /index.html HTTP/1.1Request Headers: These provide additional information about the request. Headers can indicate the type of data the client can accept, information about the browser, caching policies, and much more.
Accept: text/html, application/xhtml+xmlUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36Request Body: This is used to send data to the server, particularly for POST or PUT requests (such as form submissions or file uploads). For GET requests, the body is typically not used.
The HTTP response is the message sent from the server to the client after processing the HTTP request. It contains the requested resource or an error message, along with several components:
Response Line: Contains the HTTP version, status code, and status message.
HTTP/1.1 200 OKResponse Headers: These provide additional information about the server’s response, such as content type, caching policies, and server information.
Content-Type: text/htmlContent-Length: 1024Response Body: This is the main content of the response, such as the HTML document, image, or file that was requested.
HTTP methods define the type of action the client wants to perform on the server's resources. Some of the most common HTTP methods are:
GET: Used to request a resource from the server. It is the most common HTTP method. When you visit a webpage, your browser sends a GET request for that page.
GET /index.html HTTP/1.1POST: Used to send data to the server, often to submit forms or upload files. It is used when a client needs to submit data for processing (e.g., logging in or posting a comment).
POST /login HTTP/1.1PUT: Used to update a current resource on the server with the provided data. It is idempotent, meaning repeated PUT requests will have the same effect.
PUT /profile HTTP/1.1DELETE: Used to request the deletion of a resource from the server.
DELETE /post/123 HTTP/1.1HEAD: Similar to GET, but it only retrieves the headers of the response, not the body. It is often used for checking the status or metadata of a resource.
HEAD /index.html HTTP/1.1PATCH: Similar to PUT, but it is used for partial updates to a resource rather than replacing the entire resource.
HTTP responses include a status code that indicates the result of the request. The status codes are divided into five classes:
HTTP/1.1: The original version of HTTP widely used today. It supports pipelining, but each request-response pair is handled sequentially, which can cause delays.
HTTP/2: A significant improvement over HTTP/1.1, HTTP/2 introduced features like multiplexing (sending multiple requests over a single connection) and header compression. This reduces latency and improves performance.
HTTP/3: The newest version of HTTP, based on QUIC (Quick UDP Internet Connections). It provides further optimizations, especially around reducing latency and improving the performance of secure connections.
The HTTP protocol is essential for the functioning of the web, enabling communication between clients and servers. Understanding the basics of HTTP, including how requests and responses are structured, the different HTTP methods, status codes, and the importance of HTTPS for secure communication, is crucial for web development and ensuring the security and performance of web applications.
Open this section to load past papers