Designing HAL+JSON responses: links and embedded resources
HAL (Hypertext Application Language) is a convention for adding links and related resources to JSON resource representations. An application/hal+json document combines ordinary data fields with links and embedded. However, the HAL document is an expired individual Internet-Draft, not an RFC or an IETF standard. Use it to understand existing HAL APIs, but do not present it as a current consensus standard or the default format for every API.
HAL (Hypertext Application Language) is a convention for adding links and related resources to JSON resource representations. An application/hal+json document combines ordinary data fields with _links and _embedded. However, the HAL document is an expired individual Internet-Draft, not an RFC or an IETF standard. Use it to understand existing HAL APIs, but do not present it as a current consensus standard or the default format for every API.
Resources, links, and embedded data
A HAL resource object's ordinary JSON properties describe current resource state. The optional _links property maps link relation names to one or more link objects; _embedded maps relation names to related resource representations. A link object requires href, which can be a URI or URI template. For a template, mark templated: true.
Example: { "_links": { "self": {"href": "/orders/523"}, "invoice": {"href": "/invoices/873"}, "find": {"href": "/orders{?id}", "templated": true} }, "_embedded": { "customer": {"_links": {"self": {"href": "/customers/42"}}, "name": "Example customer"} }, "status": "shipped", "total": 10.2 }
self identifies the current resource. A relation such as invoice tells the client what the linked resource means. Use registered relation names or document custom relations. Clients should follow relations instead of guessing URL patterns.
Link only or embed the related representation?
Links keep responses smaller and let the client fetch current related data separately. _embedded can reduce requests, but an embedded representation may be partial or differ from the current representation at the target URI. For freshness-sensitive changes, follow the link to retrieve the source resource.
The expired draft makes _links and _embedded optional. Link values may be a single object or an array; Spring HATEOAS documents the resulting client compatibility choice for a single relation. Clients consuming multiple implementations should handle both shapes or the server contract should fix one shape. Document whether empty collections are omitted or represented by an empty array.
Media types
A client can request HAL with Accept: application/hal+json; the server labels the response Content-Type: application/hal+json. The API may define a different format for write request bodies. A HAL response does not imply that POST or PATCH bodies also use HAL; check the documented media type and status code.
What HAL does not define
HAL does not fully define field meaning, authentication, authorization, error format, or write forms. A _links property does not automatically reveal every possible action or required parameter. Document relation meanings, state-dependent choices, input schemas, and error handling separately. Adding HAL alone does not prove clients follow links or that the server maintains relations correctly.
Before adopting it
Verify media negotiation and response Content-Type.
Check each self and relation href is valid and accessible.
Document custom relations, their meaning, input and result.
Decide whether a relation may be object or array and how empty collections appear.
Tell clients embedded data may be partial or stale.
Account for the draft's expired status and your long-term compatibility needs.
This article separates conventions in expired HAL Internet-Draft 09 from behavior documented by Spring HATEOAS. No API server or client was run.
Sources
[IETF Datatracker: current HAL draft status](https://datatracker.ietf.org/doc/draft-kelly-json-hal/)
[IETF Internet-Draft 09: JSON Hypertext Application Language](https://datatracker.ietf.org/doc/draft-kelly-json-hal/09/)
[Spring HATEOAS reference: HAL media type](https://docs.spring.io/spring-hateoas/docs/current/reference/html/#mediatypes.hal)