The last protocol we'll cover is CoAP - Constrained Application Protocol

CoAP is a bit like REST but pared down to be as light as MQTT.


Like REST, it has GET/PUT/POST/DELETE to URLs behavior. But unlike REST, it has a very light and simple packet structure that is designed to be as minimal as possible, with binary data representation for commands and data whenever possible.

Stateless and Sessionless

HTTP/REST uses sessions but is stateless, you're expected to disconnect after data is transmitted. MQTT uses the idea of a ‘session’ or continuous connection (e.g. one socket, one session).

CoAP is not only stateless (per connection), it's sessionless: data is sent and requested at any time, somewhat like if you had MQTT but without a connection state.

That means you could run CoAP on a transport like UDP, SMS, packet radio or satellite where it’s hard to get immediate responses!

Server/Client one-to-one model

Like REST, the server doesn’t manage many-client message routing. Each client connects to the server and sends/requests data. BUT like MQTT, the client can become an ‘observer’ to get frequent asynchronous updates to a topic of interest (that way it’s not polling like traditional REST)

Watch your Transport!

About that stateless connectivity - on the Internet usually UDP is used. But that can be a problem with firewalls that often block individual ‘random’ packets and only permit outgoing TCP connections (you can run CoAP over TCP like Particle but it isn’t as common) but then you sort of lose the benefit of UDP.

This is most relevant when running on cellular & WiFi where you’ve got a direct Internet connection. Another downside is that since each message is stand-alone you cannot have any fragmentation - each message must fit in a single ZigBee, UDP, sigfox, etc. packet.

REST Interoperability

The biggest benefit to CoAP is it’s similar enough to REST that you can use it to easily transfer data between web applications because in theory its designed to be interoperable. And, there’s more stuff built into the protocol for data formatting and resource querying. But we don’t see CoAP used very often so it’s hard to say if people are really taking advantage of it!

This guide was first published on Dec 14, 2017. It was last updated on Mar 08, 2024.

This page (CoAP) was last updated on Mar 08, 2024.

Text editor powered by tinymce.