Application Protocols · Study deck
REST API Practice: Protocol Review
A smart thermostat needs a web address, or URL, for its reading.
Broker Bex is your guide for this deck.

After studying this chapter
Learning objectives
You will be able to:
- Test quiz 2: comprehensive review with a concrete scenario and pass criteria.
- Define hands-on exercise: design a smart parking rest api with explicit inputs, errors, and change rules.
- Explain: Scenario: Your IoT REST API receives a request for device data, but the device is offline.
- Explain: Mobile apps can display "Last updated 1 hour ago" without treating it as an error.
Major section
Decision Framework: When to Return 404 vs 503 vs 200 with Stale Data
Scenario: Your IoT REST API receives a request for device data, but the device is offline.
- The API request was successful -- we returned valid temperature data.
- The client can use the connectivity.status field to decide how to handle staleness.
- Device is online but unresponsive (hung firmware).
Major section
Decision Framework: When to Return 404 vs 503 vs 200 with Stale Data (continued)
Mobile apps can display "Last updated 1 hour ago" without treating it as an error.
- Offline devices are expected in IoT -- not an error condition.
- No cached data available and request requires live data.
- Cloud gateway can't reach device network (network partition).
- Key principle: IoT APIs should distinguish between "resource doesn't exist" (404), "resource exists but unavailable" (503), and "resource available but data is stale" (200 with metadata).
Major section
Concept Relationships
Resource identity decides when to use 404.
- Offline device handling requires distinguishing between no data (404) and stale data (200 with metadata), a pattern that extends to all IoT REST APIs.
Major section
Deep Dive: Reading an HTTP Message Like an Engineer
A REST response is a control signal for firmware, not just a message for a dashboard.
- For example, 202 Accepted fits a command queued for a sleeping device, while 204 No Content would falsely imply the action already completed.
- Authorization proves who is calling before anything is created.
Major section
Deep Dive: Reading an HTTP Message Like an Engineer (continued)
Returning 500 for a bad client payload makes devices retry a request that can never succeed.
- Content-Length must match the actual byte count so parsers can detect truncation or smuggling mistakes.
- The two fleet-scale traps are status masking and retry amplification.
- That line is the API contract devices actually execute.
Deck summary
Key takeaways
Scenario: Your IoT REST API receives a request for device data, but the device is offline.
- Mobile apps can display "Last updated 1 hour ago" without treating it as an error.
- Resource identity decides when to use 404.
- A REST response is a control signal for firmware, not just a message for a dashboard.
- Returning 500 for a bad client payload makes devices retry a request that can never succeed.
Retrieval practice
Recall check 1 of 4

Broker Bex says: answer from memory, then check your reasoning.
Q1A soil sensor wakes every six hours and sends a 15-byte reading. In the chapter’s illustrative battery model, CoAP uses 0.0347 mAh/day and MQTT uses 0.0438 mAh/day with a fresh TCP connection each wake. Comparing these modeled costs, which protocol saves energy and by how much?
Show answer
Answer: A see answers page
Retrieval practice
Recall check 2 of 4

Broker Bex says: answer from memory, then check your reasoning.
Q2A smart home system has a phone app that needs to directly query the current temperature from a thermostat and adjust its setpoint. The system also has a cloud dashboard subscribed to temperature updates from 5 thermostats in different rooms for historical logging. Which protocol architecture provides the most efficient solution?
Show answer
Answer: C Match the pattern: direct request/response for local control with CoAP GET/PUT; pub/sub fan-out for the dashboard with MQTT.
Retrieval practice
Recall check 3 of 4

Broker Bex says: answer from memory, then check your reasoning.
Q3A factory sends direct one-shot alerts from 200 pressure sensors over a link with 5% independent packet loss. Which configuration provides acknowledgment and retry for the alert path? A separate safety path must still meet the <100 ms action deadline under loss.
Show answer
Answer: C CoAP CON supplies acknowledgment and retransmission for direct messages.
Retrieval practice
Recall check 4 of 4

Broker Bex says: answer from memory, then check your reasoning.
Q4For the chapter’s minimal-header Ethernet/IPv4 example, a 4-byte payload ("25.3") travels with 4-byte CoAP, 8-byte UDP, 20-byte IPv4 and 14-byte Ethernet headers, with no options or security. What percentage of the 50-byte frame is overhead?
Show answer
Answer: D The minimal Ethernet/IPv4 model counts 46 header bytes in 50 total bytes: 92%.
Print reference
Answers 1 of 2
Answer key.
- A · The chapter’s illustrative daily figures give CoAP 0.0347 mAh/day and MQTT 0.0438 mAh/day: (0.0438 − 0.0347) / 0.0438 = 20.8% less modeled energy for CoAP. This is a scenario calculation, not a protocol guarantee or a two-year battery-life prediction. Measure the complete secured connection, retransmissions, radio tails, and sleep current.
- C · Match the pattern: direct request/response for local control with CoAP GET/PUT; pub/sub fan-out for the dashboard with MQTT.
Print reference
Answers 2 of 2
Answer key.
- C · CoAP CON supplies acknowledgment and retransmission for direct messages.
- D · The minimal Ethernet/IPv4 model counts 46 header bytes in 50 total bytes: 92%.