At times, you might have wondered what those four letters ‘HTTP’ at the start of every address bar in the browser meant. Well, this post will try to answer some of those questions. But before we get into what HTTP is and everything about Hypertext transfer protocol. Let us briefly overview a few terms that we might repeatedly encounter while discussing HTTP.
Web Servers
These are special computers that store necessary software for the server to respond to the request from the client. It also stores component files of websites ( for example, HTML, images, CSS style sheets, etc.) The web server establishes a connection over the internet and physically transfers the data to the client’s device. To put it simply, any computer can work as a server, but it would not be as efficient as a dedicated system.
TCP and HTTP
Transmission control protocol is the underlying principle on which HTTP is based. The client and the server establish a connection. It is only after a successful establishment, it will allow the data to be transferred over the link.
URL
It is the Universal Resource Locator that is unique to a website and acts like its address. The server looks for the files requested by the browser using the URL.
What HTTP actually is?
HTTP stands for Hyper Text Transfer protocol. It forms the medium of communication between the web server and the browser.HTTP is the language that browsers and servers use to communicate and ask for information that they require.
The working of HTTP is based on a request-response cycle. The server and browser establish a successful connection using the TCP which is underlying base for http. The cycle starts with the browser sending an HTTP request indicating what it is looking for. The server then looks for the required file having the same URL as that of the right. After fetching it, the server responds to the browser by sending it in the respective data completing a full cycle. If the server fails to find what the browser asked for, it responds with a standard HTTP message, which describes the error.
Diving deeper into Hypertext Transfer Protocol
Now, that we have a basic understanding of the request response model let us get into the nuances of the requests made by the browser and the responses of thee web server respectively.
HTTP request
The request is the initiation of the cycle by the client which in most of the cases is a web browser. The request consists of the following parts
Start line
This specifies the procedure, address of the resource, and in what format the web browser expects the data. It is further characterized into the following sections.
An http method
This describes what the web browser is asking for like whether it is asking for a resource, a resource with data response or it is submitting something causing a change at the server side. Put, Get, Head, Post are some http request method that ask server to perform different operations.
The request target
This is the address (URL) or the site where the request has to be performed. It describes the absolute path to be followed, port and domain.
GET http://iot4beginners.com an http method acting on a URL.
HTTP version
It specifies the format in which it expects the remaining message acting like an indicator of which http version to use for responding.
Headers
This passes on additional information about the requests and also about the client.
Body
It is the final part of the request. Not all requests have this element in them. The requests which intend to update server with data usually have body which carries the data. For example a “post” request which is used to send data to the server.
HTTP response
This is what server answers to the client’s request whether to fetch, put or any other such request. The response also has a specific structure to it. The following are the constituents of a standard http response.
Status line
It is the beginning of part of thee response. It describes the http version along with a status code and status text which is nothing but a description of status code in human understandable form.
A standard http response status line: HTTP/1.1 302 The request page has been temporarily moved.
Headers
Like in the request part the headers here too provide additional information about the response of the server.
Body
Similar to request structure this is the last constituent of a response. It generally carries a file having content in them. They are not present when the status code is other than for a successful response. In this case the status code is sufficient for the user to know what is going on.
HTTP and HTTPS
HTTP doesn’t account for data security and issues that arise from it subsequently. So to make the web more secure a layer of encryption using SSL/TLS was added to Hypertext Transfer Protocol aka HTTP which was called Hypertext Transfer Protocol Secure aka HTTPS. Now under this protocol the messages are encrypted on both sides i.e. on the client as well as the server side.
HTTPS provides a three front advantages over HTTP namely Encryption, Authentication and Integrity. HTTPS authenticates websites and provides a third party verified certificate ensuring that connection to this website is secure and safe. It also looks after that the content is not distorted midway or is not tampered with by third party sources.
Footnotes on HTTP
HTTP is a stateless protocol at its core. It means that neither the browser nor the server remembers the earlier request or response. Every request and response is unique independent of previous requests or response. Though there have been changes in applications running besides a standard HTTP server, which has data stored as caches/cookies, etc.
It is a client-server protocol, which means the initiation has to be by the client. The server can’t initiate the request-response cycle.
HTTP and the Internet of Things
As discussed HTTP i.e. Hypertext Transfer Protocol is a definite set of rules which two devices use to communicate efficiently with each other. Now a genuine question arises which is can we use this protocol and integrate with an IoT project. To put in another words can I use HTTP protocol for communication between different devices in my project ? But before I answer this question let us look at some peculiar characteristics of HTTP.
HTTP is a one to one communication protocol.
What this means is we cannot have many clients sending requests at the same time to the server. It will not be feasible for the server to establish a separate connection each time as required by the TCP and then start the data transfer. Also it is a one way communication but in IoT applications we require a two way data transfer.
HTTP is based on request response model.
An external stimulus generally triggers an IoT system. But as we already know HTTP aka Hypertext Transfer protocol is request response based which given the resources of an IoT system is not feasible and will put tremendous load on the limited computing resources.
Power Consumption factor.
As discussed before the HTTP is quite heavy metaphorically and hence correspondingly the hardware support that would be needed would also consume a high amount of energy. Power consumption is an important factor in designing a system. Keeping this in mind HTTP will make a system more inefficient.
The above points it clearly seem to make a point that using HTTP (Hypertext transfer protocol) for an IoT application is surely not a good idea. Theoretically you can but the system will have serious issues when you will try to scale things up. But for systems like a web browser and a web server this protocol seems indispensable.
HTTP over the years
With advancements in technology the web is also constantly evolving. The amount of data shared, the multimedia on the web, all is in a constant state of flux. With this dynamic requirement the Hypertext Transfer Protocol also kept on evolving. With HTTP/1.1 then almost after 15 years Hypertext Transfer Protocol/2 was standardised in 2015. So next time when you see those four letters ‘HTTP’ you now know what do they mean.
To know about another one such protocol called MQTT which is rather a more popular protocol in IoT world click here.