Bird
Raised Fist0

Which of the following JSON responses best uses action links to guide clients through valid state transitions when the order is in paid state?

hard🚀 Application Q15 of Q15
Rest API - HATEOAS and Linking
You want to design a REST API for an order system with states: new, paid, shipped, and cancelled. Which of the following JSON responses best uses action links to guide clients through valid state transitions when the order is in paid state?
A{ "state": "paid", "actions": { "ship": "https://api.example.com/orders/555/ship", "cancel": "https://api.example.com/orders/555/cancel" } }
B{ "state": "paid", "actions": { "pay": "https://api.example.com/orders/555/pay", "cancel": "https://api.example.com/orders/555/cancel" } }
C{ "state": "paid", "actions": { "new": "https://api.example.com/orders/555/new", "cancel": "https://api.example.com/orders/555/cancel" } }
D{ "state": "paid", "actions": { "ship": "https://api.example.com/orders/555/ship", "pay": "https://api.example.com/orders/555/pay" } }
Step-by-Step Solution
Solution:
  1. Step 1: Identify valid next states from "paid"

    From "paid", the order can be "shipped" or "cancelled" but not "pay" or "new" again.
  2. Step 2: Check which options provide correct action links

    { "state": "paid", "actions": { "ship": "https://api.example.com/orders/555/ship", "cancel": "https://api.example.com/orders/555/cancel" } } correctly offers "ship" and "cancel" actions, matching valid transitions.
  3. Final Answer:

    JSON with "ship" and "cancel" actions for "paid" state -> Option A
  4. Quick Check:

    Valid next actions for "paid" = ship, cancel [OK]
Quick Trick: Only include valid next states as action links [OK]
Common Mistakes:
MISTAKES
  • Including actions that repeat previous states
  • Missing valid next state actions
  • Confusing state names with action names

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes