Bird
Raised Fist0

Given this JSON response snippet:

medium📝 Predict Output Q4 of Q15
Rest API - HATEOAS and Linking
Given this JSON response snippet:
{"state": "pending", "actions": {"cancel": "/orders/123/cancel"}}

What is the correct next step for a client to cancel the order?
ASend a GET request to "/orders/123/cancel"
BSend a PUT request to "/orders/123/cancel"
CSend a DELETE request to "/orders/123"
DSend a POST request to "/orders/123/cancel"
Step-by-Step Solution
Solution:
  1. Step 1: Identify the action link URL

    The action link for cancel is "/orders/123/cancel".
  2. Step 2: Determine the HTTP method for state-changing actions

    State transitions like cancel usually use POST to trigger the action.
  3. Final Answer:

    Send a POST request to "/orders/123/cancel" -> Option D
  4. Quick Check:

    State change action = POST request [OK]
Quick Trick: Use POST to trigger state-changing action links [OK]
Common Mistakes:
MISTAKES
  • Using GET for state changes
  • Using DELETE on the main resource instead
  • Using PUT incorrectly for actions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes