0
0
Rest APIprogramming~20 mins

HAL format overview in Rest API - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
HAL Format 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 HAL JSON snippet?
Given this HAL JSON snippet, what is the value of the 'self' link href?
Rest API
{
  "_links": {
    "self": { "href": "/orders/123" },
    "next": { "href": "/orders/124" },
    "find": { "href": "/orders{?id}", "templated": true }
  },
  "total": 1,
  "_embedded": {
    "orders": [
      { "id": 123, "status": "shipped" }
    ]
  }
}
A"/orders{?id}"
B"/orders/123"
C"/orders/124"
D"/orders/125"
Attempts:
2 left
💡 Hint
Look inside the _links object for the 'self' key.
🧠 Conceptual
intermediate
1:30remaining
What is the purpose of the _embedded section in HAL?
In HAL format, what does the _embedded section do?
AIt contains related resources embedded inside the current resource.
BIt lists all available HTTP methods.
CIt specifies the API version used.
DIt defines HTTP headers for the response.
Attempts:
2 left
💡 Hint
Think about how HAL helps clients get related data in one response.
🔧 Debug
advanced
2:30remaining
What error does this HAL JSON cause?
This HAL JSON snippet is invalid. What error will it cause when parsed?
Rest API
{
  "_links": {
    "self": { "href": "/users/1" },
    "friends": [
      { "href": "/users/2" },
      { "href": "/users/3" }
    ]
  },
  "name": "Alice",
  "age": 30
}
ANo error, valid HAL JSON
BTypeError because 'friends' should not be an array
CKeyError because '_embedded' is missing
DSyntaxError due to missing comma between 'name' and 'age'
Attempts:
2 left
💡 Hint
Check JSON syntax carefully between properties.
📝 Syntax
advanced
2:00remaining
Which option correctly represents a templated link in HAL?
Choose the correct HAL syntax for a templated link to search orders by id.
A"search": { "href": "/orders/{id}", "templated": true }
B"search": { "href": "/orders?id", "templated": false }
C"search": { "href": "/orders{?id}", "templated": true }
D"search": { "href": "/orders?id", "templated": true }
Attempts:
2 left
💡 Hint
Templated links use curly braces with question mark for optional query params.
🚀 Application
expert
1:30remaining
How many items are in the embedded orders list?
Given this HAL JSON, how many orders are embedded inside the _embedded section? { "_links": { "self": { "href": "/orders" } }, "_embedded": { "orders": [ { "id": 101, "status": "pending" }, { "id": 102, "status": "shipped" }, { "id": 103, "status": "delivered" } ] }, "count": 3 }
A3
B4
C0
D1
Attempts:
2 left
💡 Hint
Count the number of objects inside the orders array in _embedded.