0
0
Rest APIprogramming~20 mins

Action links for state transitions in Rest API - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Action Link Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this REST API response with action links?

Given this JSON response from a REST API representing an order, what is the value of the href for the cancel action link?

Rest API
{
  "orderId": "12345",
  "status": "processing",
  "actions": {
    "cancel": {
      "href": "/orders/12345/cancel",
      "method": "POST"
    },
    "track": {
      "href": "/orders/12345/track",
      "method": "GET"
    }
  }
}
A"/orders/12345/track"
B"/orders/cancel/12345"
C"/orders/12345/cancel"
D"/cancel/orders/12345"
Attempts:
2 left
💡 Hint

Look for the cancel key inside actions and check its href value.

🧠 Conceptual
intermediate
1:30remaining
Which HTTP method is typically used for state transition actions like 'approve' or 'reject' in REST APIs?

In REST APIs, when you provide action links for state transitions such as 'approve' or 'reject' an item, which HTTP method is most appropriate to use?

APUT
BPOST
CDELETE
DGET
Attempts:
2 left
💡 Hint

Think about methods that cause a change in server state but are not idempotent.

🔧 Debug
advanced
2:00remaining
Identify the error in this action link JSON for a state transition

What error will occur when a client tries to use this action link to transition the state?

Rest API
{
  "actions": {
    "ship": {
      "href": "/orders/789/ship",
      "method": "GET"
    }
  }
}
A404 Not Found error because the URL is invalid
BNo error; the action link is valid
CSyntaxError due to missing comma
DUsing GET method for a state-changing action causes unexpected behavior
Attempts:
2 left
💡 Hint

Consider HTTP method semantics for state changes.

📝 Syntax
advanced
1:30remaining
Which option correctly represents an action link for a 'complete' state transition in JSON?

Choose the syntactically correct JSON snippet for an action link named 'complete' that uses POST method.

A{ "complete": { "href": "/tasks/456/complete", "method": "POST" } }
B{ complete: { href: "/tasks/456/complete", method: "POST" } }
C{ "complete": { "href": "/tasks/456/complete", "method": POST } }
D{ "complete": { "href": "/tasks/456/complete", method: "POST" }
Attempts:
2 left
💡 Hint

Remember JSON requires double quotes around keys and string values.

🚀 Application
expert
2:30remaining
How many action links are available for this resource and what are their HTTP methods?

Given this JSON snippet for a resource, count the number of action links and list their HTTP methods.

Rest API
{
  "id": "555",
  "status": "pending",
  "actions": {
    "approve": { "href": "/requests/555/approve", "method": "POST" },
    "reject": { "href": "/requests/555/reject", "method": "POST" },
    "cancel": { "href": "/requests/555/cancel", "method": "DELETE" }
  }
}
A3 action links: POST, POST, DELETE
B2 action links: POST, DELETE
C4 action links: POST, POST, DELETE, GET
D3 action links: GET, POST, DELETE
Attempts:
2 left
💡 Hint

Count all keys inside the actions object and note their methods.