If you followed this blog you probably know that the motto of the Web of Things community is to re-use Web protocols to build a truly interoperable Application Layer for the Internet of Things. One of the key protocols we are talking about is HTTP currently massively deployed on the Web in its 1.1 version. HTTP/1.1 is a great protocol when used correctly to build Web Services as illustrated in this book! However, it dates back from 1999. Remember this time? Back then we were using Windows 95, wired phones to call each other and the IoT term had just been coined!
Clearly, the Web evolved tremendously since then and the requirements for scale, real-time, security and performance changed quite drastically. As a result the Internet is about to fully embrace a revolution called IPv6 and the Web another called HTTP/2. The new protocol wasn’t designed specifically for the IoT but the creators of this new protocol clearly took into account some of the needs of the IoT. HTTP/2 focuses on a number of improvements over HTTP/1.1. Let’s look at the ones that are especially relevant in an IoT context:
This new version of HTTP allows multiplexing responses: that is sending responses in parallel. This fixes the “head-of-line blocking” problem of HTTP/1.x where only one request can be outstanding on a TCP/IP connection at a time. Furthermore, it fosters clients and servers to use a single TCP connection on which requests and responses are sent in streams.
This is an interesting feature for the WoT as it leads to a more efficient use of connections, which reduces the overhead of HTTP. It also leads to faster transmissions and hence potential savings in terms of battery power required to communicate. Want to see this live? Akamai developed a simple page that lets you experiment these improvements.
More efficient formats
HTTP/2 also introduces compressed headers using a very efficient and low memory compression format, unlike GZIP, the most common compression format used on top of HTTP. The compression format is called HPACK, Header Compression for HTTP/2. This new format reduces the size of each HTTP requests and responses. Additionally, while HTTP/1.1 was an ASCII protocol, i.e., a protocol transmitting ASCII characters, HTTP/2 uses binary framing, i.e., transmits binary streams of data. Binary protocols are more efficient to parse and more compact.
All of this is particularly interesting for the “Web of resource limited Things” as it means the size of packets is significantly smaller, allowing for devices with limited RAM to happily deal with HTTP/2.
Finally, HTTP/2 introduces the notion of server push. Concretely this means the server can provide content to clients without having to wait for them to send a request. If you remember, in we discussed the needs for Things to push events rather than being requested for data in several previous posts. To implement this we quite often use a Web protocol than HTTP called WebSockets. It turns out that server push in HTTP/2 could be a good way of achieving similar results!
HTTP/2 and the Web of Things
This overview of the features of HTTP/2 and what they mean for the Web of Things is by no means complete but it shows that the future of the Web will make an even better Web of Things. Interestingly enough, if you created a RESTful API based on HTTP/1.1 for your Things, you will not have to change your API at all: the underlying implementation of HTTP will change but not the API you build on top as the semantic of HTTP remain unchanged with HTTP/2!
The HTTP/2 specification was officially accepted in February 2015 and several browsers such as Chrome, Firefox and Opera started supporting it. This concretely means that the standard is being globally deployed and will soon make the Web of Things more efficient! It is also worth noting that the protocol benefited from a unique test drive over the past few years. Indeed the Spdy protocol Google crafted shared a similar aim and a similar design. As HTTP/2 is being deployed Spdy will progressively be retired a very approach and a good news for truly open Web standards.
CoAP vs HTTP/2?
In a number of previous posts we talked about a Web inspired application protocol for the Internet of Things called Constrained Application Protocol (CoAP). CoAP is interesting because it is using a REST approach but instead of using the HTTP implementation of REST it re-implements it in a way that is more adapted to very constrained devices.
What’s interesting is that a significant number of the improvements CoAP brings are also covered by HTTP/2 (e.g., binary format, header compression, etc.). However, CoAP goes an extra mile and provides further optimizations such as the use of less-resource heavy security (using DTLS), resource discovery mechanisms or the use of UDP instead of TCP. UDP is interesting for very constrained Things as the protocol is less resource hungry than TCP. UDP is not only interesting for Things but also for IoT Clouds as it is easier to scale because it does not require an actively open connection like TCP. As a consequence UDP will probably play a role in the future of the Internet and the Web of Things and it could also be through technologies like CoAP or other UDP based protocols such as Web RTC (even if there is yet to be seen if there is value beyond the hype!).
The drawback of the CoAP approach from a pure Web of today view point is that CoAP is not supported out-of-the-box by Web browsers (mainly because of its use of UDP) but can be relatively easily translated to HTTP via a software proxy. Nevertheless, as you implement the Web of Things, these technologies mentioned here are definitely worth following: as they mature and become widespread, they will surely have their say in the future of the Internet of Things, meanwhile let’s experiment with HTTP/2 for the Web of Things.
In the next post…
In a next post we will show you concrete examples of connected Things offering APIs via HTTP/2. If you can’t wait until then dig deeper into HTTP/2 and download this nice and free e-book excerpt from High Performance Browser Networking. You should also have a look at HTTP/2 implementations such as the node-http2 Node.js module which we readily tested on a number of platforms such as the Raspberry Pi.
More in the Building the Web of Things book!
This post is an extract from our book “Building the Web of Things” where we speak about HTTP/1.1 and HTTP/2 and WebSockets for Things, building bridges to CoAP, MQTT all illustrated with concrete Node.js code deployed on a Raspberry Pi.
Get the book today!