Introduction
HAL helps organize data and links in APIs so computers and people can understand and use them easily.
HAL helps organize data and links in APIs so computers and people can understand and use them easily.
{
"_links": {
"self": { "href": "/orders/123" },
"next": { "href": "/orders/124" }
},
"property": "value"
}"_links" holds URLs related to the current data.
Each link has a "href" showing where it points.
{
"_links": {
"self": { "href": "/users/1" }
},
"name": "Alice"
}{
"_links": {
"self": { "href": "/books/42" },
"author": { "href": "/authors/7" }
},
"title": "Learn HAL"
}This is a simple HAL response for a product with links to itself and its reviews.
{
"_links": {
"self": { "href": "/products/100" },
"reviews": { "href": "/products/100/reviews" }
},
"id": 100,
"name": "Coffee Mug",
"price": 12.99
}HAL uses JSON format with special "_links" and optionally "_embedded" sections.
Links help clients navigate the API without guessing URLs.
It keeps API responses consistent and easy to understand.
HAL organizes API data with links in a simple JSON format.
It helps clients find related information easily.
Using HAL makes APIs more user-friendly and discoverable.
_links section in a HAL formatted REST API response?_links in HAL_links section contains URLs pointing to related resources, helping clients navigate the API easily._links._links = URLs for related resources [OK]_links always holds related resource URLs [OK]_links with data fields_links stores authentication info_links defines API version_links object with named links, each having an href property._links with self containing an object with href. Others miss underscores, use wrong keys, or omit href._links + href [OK]_links and href keys [OK]_linkshref property inside link{
"_links": {
"self": { "href": "/orders/123" },
"customer": { "href": "/customers/456" }
},
"orderNumber": "123"
}customer link in _linkscustomer key has an href value of "/customers/456" which points to the customer's details URL.self points to the order URL "/orders/123". Other options mix order and customer IDs incorrectly._links.customer.href = /customers/456 [OK]_links for the named resource URL [OK]self with customer linkhref property{
"_links": {
"self": "/orders/123",
"items": [{ "href": "/items/1" }, { "href": "/items/2" }]
}
}href property. Here, "self" is a string, which is incorrect._links key must have an underscore. So only "self" link is wrong.href [OK]href keys [OK]_links_links key and link objects_links with each link as an object containing href. Multiple comments are an array of link objects._links with objects having href [OK]_links with objects and href for all links [OK]_links_linkPass the test and this pattern moves unknown