0
0
Rest APIprogramming~10 mins

Action links for state transitions in Rest API - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add an action link for the 'approve' transition.

Rest API
{
  "state": "pending",
  "actions": [
    {"name": "approve", "href": "/orders/[1]/approve"}
  ]
}
Drag options to blanks, or click blank then click option'
Aorder_id
Bid
C123
DorderId
Attempts:
3 left
💡 Hint
Common Mistakes
Using a literal number instead of a placeholder.
Using an underscore style that is inconsistent with the rest of the API.
2fill in blank
medium

Complete the code to add an action link for the 'cancel' transition with HTTP method DELETE.

Rest API
{
  "state": "approved",
  "actions": [
    {"name": "cancel", "href": "/orders/[1]/cancel", "method": "[2]"}
  ]
}
Drag options to blanks, or click blank then click option'
Aid
BorderId
CDELETE
DPOST
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'POST' instead of 'DELETE' for cancel action.
Using a wrong placeholder for the resource id.
3fill in blank
hard

Fix the error in the action link for the 'ship' transition by completing the HTTP method.

Rest API
{
  "state": "paid",
  "actions": [
    {"name": "ship", "href": "/orders/[1]/ship", "method": "[2]"}
  ]
}
Drag options to blanks, or click blank then click option'
Aid
BPUT
CGET
DPATCH
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'GET' which is for retrieving data, not updating.
Using 'PATCH' which is for partial updates but 'ship' implies a full state change.
4fill in blank
hard

Fill both blanks to add action links for 'approve' and 'reject' transitions with correct HTTP methods.

Rest API
{
  "state": "pending",
  "actions": [
    {"name": "approve", "href": "/orders/[1]/approve", "method": "[2]"},
    {"name": "reject", "href": "/orders/[1]/reject", "method": "[2]"}
  ]
}
Drag options to blanks, or click blank then click option'
Aid
BPOST
CPUT
DDELETE
Attempts:
3 left
💡 Hint
Common Mistakes
Using different identifiers for the two actions.
Using 'PUT' or 'DELETE' instead of 'POST' for these transitions.
5fill in blank
hard

Fill all three blanks to create an action link for 'refund' with resource id, HTTP method, and content type.

Rest API
{
  "state": "shipped",
  "actions": [
    {
      "name": "refund",
      "href": "/orders/[1]/refund",
      "method": "[2]",
      "headers": {"Content-Type": "[3]"}
    }
  ]
}
Drag options to blanks, or click blank then click option'
Aid
BPOST
Capplication/json
DPUT
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'PUT' instead of 'POST' for refund.
Omitting the content type or using an incorrect one.