Http in 3 Minutes
This blog covers the basics of the Http protocol, emphasizing its importance and discussing common types of Http methods and headers.
INTRODUCTION
Http, short for Hypertext Transfer Protocol, is an important protocol or set of rules that comes into use when web servers communicate, whether it’s for webpages, PDFs, or videos. When we browse the web, watch videos, order items online, or read the content displayed on the website through the web browser, all these variants of data are transported by Http. However, the major problem with communication over Http is the concern regarding security, which is addressed by Https. Https is a secure version of Http, the only difference being that it encrypts the requests and responses and maintains authenticity by digitally signing them through exchanging TLS certificates.
BREAKING DOWN Http
Http is much easier to comprehend than it may initially seem. Let’s explore how communication between the server and client unfolds to retrieve data. The client initiates the request, and the server responds accordingly. Information about the data type, content length, and similar details typically appear in the request, guiding the server’s response. In the anatomy of an HTTP request and response, there are primarily four components.
- Request Line
- Status Line
- HTTP Headers
- Body
Let’s examine the HTTP request and response and analyze the components used in HTTP communications.
Request Line
The initial line in the HTTP request includes the HTTP method, the requested homepage (“/”), and the protocol version in use. HTTP methods act as a way for the client to communicate their intended action when initiating an HTTP request. Different types of methods exist, and let’s explore a few of them.
1. GET Request: Retrieves information from a web server.
2. POST Request: Submits data to the web server.
3. PUT Request: Updates existing information in the web server.
4. DELETE Request: Deletes information or records from a web server.
HTTP Headers
HTTP request and response headers are elements within an HTTP request that cater extra details or metadata about the request or response. Now, let’s explore a few typical HTTP headers.
1. Host: Specifies the host server which website you require.
2. User-Agent: Informs the server about the browser software and version.
3. Connection: Controls whether the network connection stays open after the current transaction finishes.
4. Referer: Provides the URL of the referring page from which the current request was initiated.
5. Content-Type: Informs the client about the type of data being returned.
6. Content-Length: Indicates the size of the message body, in bytes, sent to the recipient.
Status Line
The status line is the first line of an HTTP response, it contains essential information about the status and version of the response. It typically follows the format:
- HTTP Version: Indicates the version of the HTTP protocol used in the response.
- Status Code: Provides a three-digit numerical code that indicates the outcome of the server’s attempt to fulfill the client’s request. Common status codes include:
200 OK
: The request was successful.404 Not Found
: The requested resource could not be found.500 Internal Server Error
: A generic error message indicating a problem on the server.
Body
Lastly, HTTP body, also known as the message body or payload, is the part of an HTTP request or response that carries the actual data being sent between the client and the server. It comes after the headers in both HTTP requests and responses.
These components primarily collaborate and interconnect to deliver web services. This was a fundamental overview of the HTTP protocol.