Bird
0
0

Given this JSON response snippet from a REST API:

medium📝 Predict Output Q13 of 15
Rest API - HATEOAS and Linking
Given this JSON response snippet from a REST API:
{
  "state": "pending",
  "actions": {
    "approve": "https://api.example.com/items/42/approve",
    "reject": "https://api.example.com/items/42/reject"
  }
}

What will happen if the client calls the URL in the "approve" action link?
AThe item state will change to approved
BThe item will be deleted
CThe client will receive an error because the URL is invalid
DThe item state will remain pending
Step-by-Step Solution
Solution:
  1. Step 1: Understand the meaning of the "approve" action link

    The "approve" link is provided as a next step to change the state from "pending" to "approved" by calling that URL.
  2. Step 2: Predict the effect of calling the approve URL

    Calling the approve URL triggers the state transition to "approved" as intended by the API design.
  3. Final Answer:

    The item state will change to approved -> Option A
  4. Quick Check:

    Calling "approve" URL = state changes to approved [OK]
Quick Trick: Action link name hints the state change [OK]
Common Mistakes:
  • Assuming the URL deletes the item
  • Thinking the URL is invalid
  • Believing state stays the same after action

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes