CoAP (Constrained Application Protocol)
What you'll learn: How CoAP enables RESTful communication for resource-constrained IoT devices using a lightweight UDP-based architecture, and how it compares to traditional HTTP/HTTPS.
What Is CoAP?
CoAP is a specialized web transfer protocol designed for tiny, low-power devices like sensors and microcontrollers. Think of it as "HTTP's minimalist cousin"—it follows REST principles (GET, POST, PUT, DELETE) but strips away all the overhead that would overwhelm a battery-powered sensor.
UDP-Based Architecture
Unlike HTTP's reliance on TCP, CoAP uses UDP as its transport layer. This matters because:
- No connection handshake overhead: TCP's three-way handshake wastes precious energy and bandwidth on constrained devices
- Smaller packets: CoAP headers are ~4 bytes vs. HTTP's hundreds
- Asynchronous messaging: Perfect for devices that sleep between transmissions
CoAP implements its own lightweight reliability layer on top of UDP, using confirmable (CON) and non-confirmable (NON) message types—giving developers choice between guaranteed delivery and minimal overhead.
Comparison with HTTP/HTTPS Patterns
| Feature | HTTP/HTTPS | CoAP |
|---|---|---|
| Transport | TCP | UDP |
| Header Size | ~200+ bytes | ~4 bytes |
| Default Port | 80/443 | 5683/5684 |
| Resource Model | REST URIs | REST URIs |
| Security | TLS | DTLS |
| Observation | Long-polling/WebSockets | Native observe option |
CoAP supports observe patterns natively, letting clients subscribe to resource changes—like MQTT's publish-subscribe but with REST semantics. Security uses DTLS (Datagram TLS) instead of TLS, preserving the UDP benefits while adding encryption.
Key Takeaway: CoAP brings RESTful web patterns to constrained IoT devices through a UDP-based architecture that minimizes overhead, making it ideal for battery-powered sensors while maintaining familiar HTTP-like semantics—but this efficiency comes with security trade-offs requiring DTLS and careful implementation.