Skip to content

Instantly share code, notes, and snippets.

@treyhunner
Created February 18, 2012 02:19
Show Gist options
  • Select an option

  • Save treyhunner/1856954 to your computer and use it in GitHub Desktop.

Select an option

Save treyhunner/1856954 to your computer and use it in GitHub Desktop.
Embedding links in HAL+JSON
{
"queue_status": "running",
"_embedded": {
"jobs": [
{
"_links": {
"self": { "href": "/queue/job1" },
}
"status": "queued"
},
{
"_links": {
"self": { "href": "/queue/job2" },
}
"status": "running"
},
{
"_links": {
"self": { "href": "/queue/job2" },
"output": { "href": "/output2" }
}
"status": "complete"
}
]
}
}
{
"queue_status": "running",
"jobs": [
{
"_links": {
"self": { "href": "/queue/job1" },
}
"status": "queued"
},
{
"_links": {
"self": { "href": "/queue/job2" },
}
"status": "running"
},
{
"_links": {
"self": { "href": "/queue/job2" },
"output": { "href": "/output2" }
}
"status": "complete"
}
]
}
@mikekelly

Copy link
Copy Markdown

So the difference is:

document._embedded.jobs[0].status
// vs..
document.jobs[0].status

Although _embedded may seem like noise, it's valuable to have HAL defined this way because it allows generic libraries/browsers to be written that can efficiently distinguish embedded resources from standard JSON properties that belong to the resource.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment