CoAP · Study deck

CoAP Method/Multicast Contracts

A room controller wants a lamp on.

Broker Bex is your guide for this deck.

methodcodesmulticast
Broker Bex, the module guide, in a scene from this chapter.
iotclass.org

After studying this chapter

Learning objectives

You will be able to:

  • Map CoAP GET, POST, PUT, and DELETE to compact method codes and expected response-code families.
  • Use safe and idempotent method properties to decide what can be retried, cached, or sent by multicast.
  • Explain why multicast CoAP requests are Non-confirmable and why replies are unicast responses spread across a Leisure window.
  • Capture method, response-code, Location option, Token, and multicast-response evidence for a CoAP API review.
iotclass.org

Major section

Start With the Duplicate Command

A lost reply may cause a retry.

  • The safe design must show which requests can repeat and which physical actions must happen only once.
  • An application programming interface is a defined way for software parts to request work or data; API is its short name.
  • A protocol means the shared rules for a message exchange.

Key terms

CoAP
CoAP means Constrained Application Protocol, a compact web-style message system for small devices.
iotclass.org

Major section

Start With the Duplicate Command (continued)

CoAP means Constrained Application Protocol, a compact web-style message system for small devices.

  • This runway does not prove every group or resource design is safe.
  • The deeper sections explain method codes, repeat-safe behavior, created-resource locations, multicast response timing, and the evidence each result requires.
  • A light switch can safely retry a GET /state, but retrying a badly designed POST /toggle might turn the light back off.
iotclass.org

Major section

Overview: Four Methods, Familiar REST Semantics, Compact Codes

Every response carries a Code too, grouped into families.

  • Class 2 is success ( 2.05 Content for a GET, 2.01 Created, 2.04 Changed, 2.02 Deleted).
  • Class 4 is a client error ( 4.04 Not Found, 4.05 Method Not Allowed, 4.00 Bad Request).
  • Safe: it never changes state.
CoAP GET, POST, and PUT method exchanges with their compact response codes.
CoAP GET, POST, and PUT method exchanges with their compact response codes.
iotclass.org

Major section

Overview: Four Methods, Familiar REST Semantics, Compact Codes (continued)

Class 5 is a server error ( 5.00 Internal Server Error, 5.03 Service Unavailable).

  • A client can branch on the class alone before it ever parses a payload.
  • On the wire, the method names become tiny numeric method codes: GET is 0.01, POST is 0.02, PUT is 0.03, and DELETE is 0.04.
  • Success is 2.05 Content with the representation in the payload.
iotclass.org

Major section

Practitioner: Safe and Idempotent Decide What You Can Retransmit and Multicast

If the same device receives POST /readings three times without an application record ID, it may store three readings.

  • A safe method never changes server state; only GET is safe.
  • Deleting twice still ends deleted; retry is safe.
  • A duplicated POST may create twice; rely on server dedup.

Why it matters

If a thermostat receives the same PUT /config/interval payload three times because ACKs were lost, the state is still "interval = 30 seconds"; the duplicate packets are annoying but not semantically dangerous.

iotclass.org

Major section

Under the Hood: What the Codes Say, and Why Multicast Has No ACK

Response codes carry more than success or failure.

  • Multicast changes the messaging layer, not the meaning of the codes.
  • A server that has nothing relevant may simply stay silent.
  • 2.01 Created Answer to a POST/PUT that made a resource; carries Location options naming the new URI.

Key terms

Idempotent
Idempotent means the resource remains absent; later status may be Deleted or Not Found.
2.05 Content
2.05 Content is the answer to a GET.
iotclass.org

Major section

Under the Hood: What the Codes Say, and Why Multicast Has No ACK (continued)

To keep many servers from replying in the same instant and swamping a constrained link, each server waits a random interval within a Leisure period before answering, and its reply is a unicast Non-confirmable message.

  • The client therefore has to tolerate anywhere from zero to many responses, correlating each one to its request by the Token.
  • The outbound request has one Token and one multicast destination, then the client receives zero, one, or many unicast replies from different source endpoints.
  • Idempotent means the resource remains absent; later status may be Deleted or Not Found.
iotclass.org

Major section

Retry a Desired State, Then Count Discovery Replies

For a worked method example, assume the lamp starts off.

  • A POST that means toggle changes off to on on its first execution, then on to off if the server executes it again as a new operation.
  • The compact Code byte carries a class and detail.

Key terms

If their unicast replies
If their unicast replies are spread over an illustrative 6 s response window, the mean offered response rate is 2 replies per second.
CoAP GET, POST, and PUT method exchanges with their compact response codes.
CoAP GET, POST, and PUT method exchanges with their compact response codes.
iotclass.org

Major section

Retry a Desired State, Then Count Discovery Replies (continued)

Message-level duplicate detection helps within its scope, but it does not make every later POST repeat-safe.

  • These outcomes explain why the client must interpret response codes before treating a returned body as the requested content.
  • This calculation explains the byte value; it does not mean that every successful method returns the same response.
  • Created content has its own location, which the client retains from the returned Location options.
iotclass.org

Major section

Retry a Desired State, Then Count Discovery Replies (continued)

If their unicast replies are spread over an illustrative 6 s response window, the mean offered response rate is 2 replies per second.

  • That average does not guarantee even spacing: random delays can still place replies close together.
  • The discovery client must accept content from zero, one or many endpoints and preserve each source address.
  • Missing content can also result from loss, scope, sleeping endpoints or access policy.
iotclass.org

Deck summary

Key takeaways

A lost reply may cause a retry.

  • CoAP means Constrained Application Protocol, a compact web-style message system for small devices.
  • Every response carries a Code too, grouped into families.
  • Class 5 is a server error ( 5.00 Internal Server Error, 5.03 Service Unavailable).
  • If the same device receives POST /readings three times without an application record ID, it may store three readings.
iotclass.org

Retrieval practice

Recall check 1 of 3

Broker Bex says: answer from memory, then check your reasoning.

Q1A CoAP client sends GET to a resource that does not exist on the server. What response Code should it expect?

A4.04 Not Found.
B2.05 Content, empty body.
C5.00 Internal Server Error, because the server could not find the resource.
DRST, because the message could not be processed.
Show answer

Answer: A 4.04 Not Found is the class 4 (client error) response for a resource that does not exist, mirroring HTTP 404.

iotclass.org

Retrieval practice

Recall check 2 of 3

Broker Bex says: answer from memory, then check your reasoning.

Q2You want to discover CoAP resources across a subnet with one request. Which message type and method are correct?

AA Non-confirmable GET to /.well-known/core.
BA Confirmable GET to the multicast group so every node acknowledges.
CA Non-confirmable POST to the multicast group to register interest.
DA Confirmable PUT to /.well-known/core to write a shared registry.
Show answer

Answer: A Multicast requests must be Non-confirmable, and GET is the safe, idempotent read used for discovery at /.well-known/core on the All CoAP Nodes multicast address.

iotclass.org

Retrieval practice

Recall check 3 of 3

Broker Bex says: answer from memory, then check your reasoning.

Q3A client POSTs a new sensor record and the server assigns its URI. Which response and options best represent success?

A2.05 Content, because the server returns the stored record.
B2.04 Changed, because adding the record changes the collection.
C2.01 Created with Location options for the new resource.
D2.02 Deleted, because creating a record replaces the old one.
Show answer

Answer: C When POST creates a subordinate resource the server assigns, it returns 2.01 Created and reports the new URI through Location options.

iotclass.org

Print reference

Answers

Answer key.

  1. A · 4.04 Not Found is the class 4 (client error) response for a resource that does not exist, mirroring HTTP 404.
  2. A · Multicast requests must be Non-confirmable, and GET is the safe, idempotent read used for discovery at /.well-known/core on the All CoAP Nodes multicast address.
  3. C · When POST creates a subordinate resource the server assigns, it returns 2.01 Created and reports the new URI through Location options.
iotclass.org