Including related entities

To reduce the number of HTTP requests, some endpoints support including related entities in the response. Let’s take GET pages/:id.json for example, which has an space relationship;

Request: GET .../pages/1.json

Response:

{
	"page": {
		...
		"space": { "id": 42, "type", "spaces" },
		...
	}
}

If you were to request GET pages/1.json?include=spaces, you would get the following:

{
	"page": {
		...
		"space": { "id": 42, "type", "spaces" },
		...
	},
	"included": {
		"spaces": {
			"42" :{
                ...
            }
		}
	}
}

Note: the query parameter value matches the relationship property type (spaces).

As you can see, there’s now another root property called included. This contains a property for each entity type included, spaces in this case. These properties are always maps with the id being the key, the value will contain full entity models (resource objects), i.e. space models in this case. This is the full spaces model with all of its properties including its resource identifier objects.

It’s possible to include multiple relationships in one request; e.g. include=spaces,users. It’s possible to include indirect relationships; e.g. include=spaces.users,spaces. This will include the space the page is linked to, as well as the user information for the space ie who created it, last updated etc.

All endpoints with resource identifiers objects support the included feature.

Feedback

If you have any feedback or suggestions, feel free to contact us at api@teamwork.com.