CoAP Request-Response Model
Definition
The CoAP request-response model is an application-layer communication pattern in which a client sends a request message to a server to perform an operation on a resource, and the server replies with a response message that may confirm the request, return data, or report an error. CoAP supports RESTful methods such as GET, POST, PUT, and DELETE, and it is optimized for constrained devices, lossy links, and asynchronous communication.
Main Content
1. RESTful Resource Interaction
- CoAP follows the REST architecture, where everything of interest is treated as a resource identified by a URI such as
coap://sensor.local/temp. - Clients use standard methods to interact with resources:
GETto read data, such as a temperature valuePOSTto create or process dataPUTto update a resourceDELETEto remove a resource- Resources are usually represented in compact formats like plain text, JSON, CBOR, or binary, which keeps message size small for constrained networks.
- Example: A smart thermostat client may send
GET /temperatureto retrieve the current reading, orPUT /setpointto change the desired temperature.
2. Message Exchange and Reliability
- CoAP runs primarily over UDP, so it does not rely on a built-in connection like TCP; instead, it uses a lightweight reliability mechanism at the message layer.
- Requests and responses can be carried in different message types:
- Confirmable (CON) messages require an acknowledgment to ensure delivery
- Non-confirmable (NON) messages are sent without acknowledgment when reliability is less critical
- Acknowledgment (ACK) messages confirm receipt of CON messages
- Reset (RST) messages indicate that a message was received but could not be processed or matched
- Each request includes a Message ID and usually a Token:
- The Message ID helps detect duplicates and supports reliability
- The Token matches a response to the original request
- Example: A sensor node sends a CON
GETrequest to a server; the server replies with an ACK and the requested data, ensuring the client knows the message was received.
3. Request-Response Patterns and Advanced Features
- CoAP supports both synchronous and asynchronous response behavior:
- In synchronous mode, the server responds immediately with the result
- In asynchronous mode, the server may first send an ACK to stop retransmissions and later send the actual response when processing is complete
- CoAP also supports proxying and observation:
- Proxies can forward requests and responses between CoAP and HTTP or between separate CoAP domains
- The Observe extension allows a client to register interest in a resource and receive notifications whenever it changes, extending the request-response model into a lightweight publish-like pattern
- Response codes are structured similarly to HTTP but are optimized for CoAP, such as:
2.05 Contentfor a successful GET2.01 Createdfor a successful POST4.04 Not Foundif a resource does not exist5.00 Internal Server Errorfor server-side failures- Example: A weather sensor client sends
GET /humidityand later receives periodic updates using Observe whenever humidity changes.
Working / Process
- The client discovers or already knows the resource URI and sends a CoAP request using a method such as GET, POST, PUT, or DELETE.
- The request is sent as a CoAP message over UDP with the appropriate message type, Message ID, and Token so the server can process it and match the reply.
- The server processes the request, sends the correct response code and payload, and if needed uses ACKs, retransmissions, or asynchronous delivery to ensure reliable communication.
Advantages / Applications
- Very low overhead compared with HTTP, making it ideal for battery-powered IoT devices with limited CPU, memory, and bandwidth.
- Suitable for unreliable networks because it includes lightweight reliability, retransmission, and duplicate detection mechanisms.
- Commonly used in smart homes, industrial monitoring, building automation, environmental sensing, and device management where many small devices exchange resource-based data.
Summary
- CoAP uses a lightweight REST-based request-response model for constrained IoT environments.
- It supports efficient communication over UDP with methods like GET, POST, PUT, and DELETE.
- Reliability is handled through confirmable messages, acknowledgments, and message identifiers.
- The model is especially useful for small embedded devices that need simple, scalable, and low-power communication.