Skip to content

Embedded content

Work in progress

This warning will be removed once this page has passed testing.

Let's take a look at this resource model:

A simple Library resource model

tl;dr

Deeper walkthrough

Work in progress

When we get the home resource...

...we get back:

json
{
    "_links": {
        "self": {
            "href": "/",
            "_note": "Home resource for library system"
        },
        "library": {
            "href": "/libraries{?links_only}",
            "templated": true
        },
        "member": {
            "href": "/members{?links_only}",
            "templated": true
        },
        "book": {
            "href": "/books{?links_only}",
            "templated": true
        }
    }
}

Each of these resources is a collection, i.e. there are many libraries, each with many members, holding many books, etc.

When a HAL-oriented API serves a collection resource, the actual list is found in the _embedded property.

For example this call...

The JSON representation of the member collection is as follows:

json
{
  "_links": {
    "self": { "href": "/members"  },
    "item": {
      "href": "/members/{id}",
      "templated": true
    },
    "search": {
      "href": "/members{?where,sort,max_results,page,embed}",
      "templated": true
    },
    ...
  },
  "_meta": {
    "page": 1,
    "max_results": 1000,
    "total": 6
  },
  "_embedded": {
    "member": [
      {
        "_id": "67ea066d1dd141f4499b9528",
        "name": "John Doe",
        "_links": {
          "self": { "href": "/members/67ea066d1dd141f4499b9528" },
          "book": { "href": "/members/67ea066d1dd141f4499b9528/books" },
          ...
        }
      },
      {
        "_id": "67ea06741dd141f4499b9529",
        "name": "Sally Jane",
        "_links": {
          "self": { "href": "/members/67ea06741dd141f4499b9529" },
          "book": { "href": "/members/67ea06741dd141f4499b9529/books" },
          ...
        }
      },
      ...
      ...
    ]
  }
}

Released under the MIT License.