How y'all doing!? I am back with another amazing and intriguing topic!?
Have you ever wondered that while entering a URL of any website why does it require "HTTP" or "HTTPS" to be present there in the URL? or what is even this HTTP!??
If you are the one who is struggling to find answers to all these questions then you have landed on the right blog. So the topics that will be covered under this blog are as follows:
- What is HTTP?
- Characteristics of HTTP.
- What all HTTP methods are there and how do all of them differentiate from one another!?
- HTTP Requests.
- HTTP headers.
- HTTP Responses.
- HTTP status code.
Before diving into these topics, let's discuss a few terms you might come across in this blog.
- PROTOCOL : A protocol is a set of instructions or rules and guidelines needed and required for communicating and transferring data between two parties.
Suppose, there's a sender who wants to send the data to the receiver. Now to understand this message that is being transferred there must be some protocols that run on both sender and receiver machines.
URL : Uniform Resource Locator is a reference (an address) to a resource on the Internet.
Idempotent Method : An idempotent method means that the result of a successfully performed request is independent of the number of times it is executed.
So without any further delay let's quickly dive into it!!
What is HTTP!?
Hypertext Transfer Protocol (HTTP) or Hypertext Transfer Protocol Secure(HTTPS) is an application layer protocol that is the foundation for any data exchange on the web. It is designed to enable communications between clients and servers. It works as a request-response protocol between both the client and server.
Characteristics of HTTP
- Based on TCP/IP protocol: TCP/IP is a connection-oriented protocol. HTTP itself is not reliable but uses TCP to achieve reliability.
- Connectionless Protocol: What do I meant by this statement is that once the connection is established and the client has made the request, the client disconnects from the server. Only after the server processes the request, it re-creates the connection with the client to send a response back.
- Stateless Protocol: This means that every HTTP request the server receives is independent and does not relate to requests that came prior to it. Let's try to understand it with the help of an example.
The server after giving the response to the request that was made by the client ends the connection that was established between them. And with it, the information between them also gets lost.
- This HTTP request could be either persistent(HTTP/1.1) or non-persistent(HTTP/1.0). To give a quick and brief overview of both these terms, persistent means that it does not require connection setup again and again. And non-persistent means that it requires connection setup again and again for each object to send.
There are a set of methods that identifies the action that needs to be performed at the given resource.
A few different types of HTTP and generally used methods are:
GET HTTP method
- Get methods are the most common and widely used methods and often the default method in http.
- Used to retrieve the data from the server at the specific resource.
- Only gets the data and do no modification to any resources, therefore is considered a safe and important method.
- Valid get request return 200 status code.
POST HTTP method
- Used to send data, and create or update a resource.
- The data sent to the server is stored in the request body of the HTTP request.
- POST request is non-idempotent.
Calling a POST request repeatedly may have side effects of creating the same resource multiple times.
GET vs POST
It mutates the data on the backend server(by creating or updating a resource), as opposed to GET method which does not change any data.
PUT HTTP method
- Similar to POST.
- If a PUT request creates a resource, the server will respond with a 201 status code.
- If the request modifies existing resources the server will return a 200 status code or 204(no content) status code.
POST vs PUT
The difference is that PUT requests are idempotent i.e. calling the PUT requests multiple times will always produce the same result.
HTTP Requests mainly comprise four parts, i.e. HTTP method, URI, HTTP header, and body.
- HTTP method specifying what to do with the resource.
- The URL of the resource is used to find the resource on the server.
- Also the HTTP protocol version stating which version is being used. (Ex. HTTP/ 1.0 or HTTP/1.1)
- HTTP headers comprising the information of the request.
The headers are used to pass more information about the request so that using the request headers the server knows how to deal with the information the client is demanding.
Explanation of few components it has:
- Host: where the request hits.
- User-Agent: The User-Agent request header is a character string that lets servers and network peers identify the application, operating system, vendor, and/or version of the requesting user agent.
- Authorization: Contains the credentials information to authenticate a user through a server.
- Cookie: The Cookie HTTP request header contains stored HTTP cookies associated with the server.
- Body(optional): Contains the parameter(input value) passed to the server in case of HTTP methods like POST, PUT, etc.
HTTP Response is the server's response as a result of the client's request.
It mainly comprises status code, headers(containing, content-type, set-cookie, content-length, etc.), body.
HTTP status code
Specifies whether the specific HTTP request has successfully completed. Responses are mainly grouped into five classes.
- Informative responses.
- Successful responses.
- Redirection messages.
- Client error responses.
- Server error responses.
And here we come to the end of this blog!!
Thanks for giving it a read. I hope this might have helped you! 😊
Will be back with more blogs...See yaa 😉!!
till then stay safe and healthy, study more, share more, gain more and grow more!!🤗