Chapter 13. CoAP: REST for Embedded Systems

The Constrained Application Protocol[58] is a protocol designed for use in low-power embedded environments like home automation systems. CoAP is inspired by HTTP and can be used to publish hypermedia-driven RESTful APIs, but it’s a very different protocol from HTTP. CoAP brings a web-like architecture to a highly constrained environment: an “Internet of Things” in which a lot of small, cheap computers communicate over a low-capacity network.

CoAP is designed to live with severe limitations on electricity consumption, network bandwidth, and processing power. Its world resembles the ARPAnet of the 1970s rather than the network people enjoy today. CoAP requests and responses are very small. On a network that runs over home power lines, a CoAP message shouldn’t be larger than about 1,024 bytes. On a low-power wireless network, you probably don’t want to go above 80 bytes.

But in terms of network layout, these environments look a lot like the World Wide Web. There’s no single “API provider” that serves a lot of similar clients. Instead, devices from many different manufacturers are placed into the same room, seemingly at random. Some of them have data to provide. Some have the ability to make things happen in the real world. Very rarely, one of these devices might get a human’s attention long enough to answer a yes-or-no question.

These devices must locate each other over the network, learn each other’s capabilities, and ...

Get RESTful Web APIs now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.