Chapter 6. Access: Web APIs for Things
This chapter covers
- Designing APIs for Things based on the REST principles
- Implementing RESTful Things with HTTP and WebSockets
- Representing resources with JSON and MessagePack
- Allowing cross-site requests using CORS
- Using WebSockets and web hooks to implement real-time communication with Things
- Looking at HTTP/2, the future of HTTP
By now, it should be clear that the central idea behind the Web of Things is to make it easy for devices, services, and applications to talk to each other by using patterns and standards that are similar to anything else on the web.
In this chapter, we’ll describe in detail what those patterns are and will show you how to use them to implement web APIs for physical objects. Before jumping headfirst into code, a little bit of theory is needed, so we’ll start by exploring the fundamentals of the modern web architecture. First, we’ll introduce REST, which defines the core architecture of the web. Afterward, we’ll propose a set of guidelines and a methodology to design RESTful APIs for physical devices so that HTTP clients can easily read data from their sensors or send control commands to them. Finally, we’ll expose the limitations of REST APIs over HTTP when it comes to real-time sensor data and notifications, and we’ll describe how the latest developments in web technologies such as WebSockets can be used to provide push notifications for the Web of Things.