HTTP (Hypertext Transfer Protocol) is a fundamental protocol of the Internetenabling the transfer of data between a client and a server. It is the foundation of data communication for the World Wide Web. HTTP provides a standard between a web browser and a web server to establish communication. It is a set of rules for transferring data from one computer to another.
HTTP Connection
Note: Data such as textimages and other multimedia files are shared on the World Wide Web. Whenever a web user opens their web browserthe user indirectly uses HTTP. It is an application protocol that is used for distributedcollaborativehypermedia information systems.
Features
Stateless: Each request is independent and the server doesn't retain previous interactions' information.
Text-Based: Messages are in plain textmaking them readable and debuggable.
Client-Server Model: Follows a client-server architecture for requesting and serving resources.
Request-Response: Operates on a request-response cycle between clients and servers.
Request Methods: Supports various methods like GETPOSTPUTDELETE for different actions on resources.
Note: It was renamed as Hyper-Text Transfer Protocol QUIC (HTTP/3) and developed by Google.
Methods of HTTP
GET: Used to retrieve data from a specified resource. It should have no side effects and is commonly used for fetching web pagesimagesetc.
POST: Used to submit data to be processed by a specified resource. It is suitable for form submissionsfile uploads and creating new resources.
PUT: Used to update or create a resource on the server. It replaces the entire resource with the data provided in the request body.
PATCH: Similar to PUT but used for partial modifications to a resource. It updates specific fields of a resource rather than replacing the entire resource.
DELETE: Used to remove a specified resource from the server.
HEAD: Similar to GET but retrieves only the response headersuseful for checking resource properties without transferring the full content.
OPTIONS: Used to retrieve the communication options available for a resourceincluding supported methods and headers.
TRACE: Used for debugging purposes to echo the received request back to the clientthough it's rarely used due to security concerns.
CONNECT: Used to establish a tunnel to the server through an HTTP proxycommonly used for SSL/TLS connections.
HTTP Request/Response:
HTTP is a request-response protocolwhich means that for every request sent by a client (typically a web browser)the server responds with a corresponding response. The basic flow of an HTTP request-response cycle is as follows:
Client sends an HTTP request: The client (usually a web browser) initiates the process by sending an HTTP request to the server. This request includes a request method (GETPOSTPUTDELETEetc.)the target URI (Uniform Resource Identifiere.g.a URL)headers and an optional request body.
Server processes the request: The server receives the request and processes it based on the requested method and resource. This may involve retrieving data from a databaseexecuting server-side scripts or performing other operations.
Server sends an HTTP response: After processing the requestthe server sends an HTTP response back to the client. The response includes a status code (e.g.200 OK404 Not Found)response headers and an optional response body containing the requested data or content.
Client processes the response: The client receives the server's response and processes it accordingly. For exampleif the response contains an HTML pagethe browser will render and display it. If it's an image or other media filethe browser will display or handle it appropriately.
HTTP Request/Response
HTTP Request Circle
This table explains how HTTP requests work when you visit a webpage and what happens behind the scenes. Here’s a breakdown of the process:
Requested Resource
Resource Type
Server Response
HTML Page
HTML
Server sends HTML file
Style Sheet (CSS)
CSS
Server sends CSS file
Image (JPG)
Image (JPG)
Server sends JPG image
JavaScript Code
JavaScript (JS)
Server sends JS file
Data (XML or JSON)
Data
Server sends XML/JSON data
Requested Resource: This is the type of content you're asking the server to send you. For exampleit could be an HTML pagea sheet (CSS)an image or JavaScript code.
Resource Type: This tells the server what kind of file or data you need. For examplean HTML page would be of type HTMLa sheet is CSSan image would be an image type (like JPG)JavaScript code is of type JS and data could be in formats like XML or JSON.
Server Response: After receiving the requestthe server sends back the correct file or data based on the request. For exampleif you requested an HTML pagethe server sends back the HTML file or if you requested an imagethe server sends back the image file.
Examples for each request
HTML Page: If you want a webpagethe server sends back the HTML content.
CSS: For styling a webpagethe server sends the CSS file.
Image: If you ask for a picture (like a JPG)the server sends the image.
JavaScript: If you need functionality for the pagethe server sends the JS code.
Data: If you're looking for specific data (like in XML or JSON format)the server sends that data back.
Note: The "HTTP Request Circle" is just showing how a web browser requests different kinds of resources from a server and the server responds by sending the corresponding files or data.
Overview of HTTP Request and Response Components
Concept
Description
HTTP Request Headers
Text information in key-value pairs sent with every HTTP requestconveying details such as client's browserrequested data and more.
HTTP Request Body
Contains data being submitted to the web serversuch as form inputsauthentication details or other payload data.
HTTP Response
Sent by the server in answer to an HTTP requestconsisting of an HTTP status coderesponse headers and optional response body.
HTTP Status Codes
3-digit codes indicating the outcome of an HTTP requestcategorized into 1xx (Informational)2xx (Success)3xx (Redirection)4xx (Client Error) and 5xx (Server Error) blocks.
HTTP Response Headers
Provide important information like data formatlanguage and content type in the responsehelping clients interpret the data correctly.
HTTP Response Body
Contains the requested information sent by the serversuch as HTML content for webpagesJSON data or other data based on the client's request.
History of HTTP
Tim Berners-Lee and his team at CERN are indeed credited with inventing the original HTTP protocol.
HTTP version 0.9 was the initial version introduced in 1991.
HTTP version 1.0 followed in 1996 with the introduction of RFC 1945.
HTTP version 1.1 was introduced in January 1997 with RFC 2068later refined in RFC 2616 in June 1999.
HTTP version 2.0 was specified in RFC 7540 and published on May 142015.
HTTP version 3.0also known as HTTP/3is based on the QUIC protocol and is designed to improve web performance.
Advantages
Platform independence: Works on any operating system
Compatibility: Compatible with various protocols and technologies
Efficiency: Optimized for performance
Security: Supports encryption for secure data transfer
Disadvantages
Lack of security: Vulnerable to attacks like man in the middle
Performance issues: Can be slow for large data transfers
Statelessness: Requires additional mechanisms for maintaining state