Bird
Raised Fist0

What will be the output of this pseudo-code when following hypermedia links?

medium📝 Predict Output Q5 of Q15
Rest API - HATEOAS and Linking
What will be the output of this pseudo-code when following hypermedia links?
response = {"links": {"self": "/orders/1", "cancel": "/orders/1/cancel"}}
print(response["links"]["cancel"])
AKeyError
B/orders/1
C/orders/cancel
D/orders/1/cancel
Step-by-Step Solution
Solution:
  1. Step 1: Access the "cancel" link in the "links" dictionary

    The code accesses response["links"]["cancel"], which is "/orders/1/cancel".
  2. Step 2: Print the value

    The print statement outputs the string "/orders/1/cancel" exactly.
  3. Final Answer:

    /orders/1/cancel -> Option D
  4. Quick Check:

    Accessing "cancel" link [OK]
Quick Trick: Access links by their relation names in response objects [OK]
Common Mistakes:
MISTAKES
  • Confusing "cancel" with "self" link
  • Expecting a KeyError due to missing key
  • Misreading the dictionary structure

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes