Aller au contenu
uencoder

Spécification HATEOAS / HAL

Référence pour Hypertext Application Language (HAL) pour embedding hypermedia links en JSON responses.

HAL Structure

HAL embeds links in resources using a _links property containing rel-to-link mappings. Each link has an href and optional properties like type, title, or templated. Embedded resources use _embedded with the same rel structure. The format is minimal, adding only two reserved properties to standard JSON. HAL enables HATEOAS: clients discover actions via links rather than hardcoded URLs.

_links
Hypermedia links
rel -> { href }
_embedded
Sideloaded resources
embedded objects
templated
URI templates
RFC 6570

HATEOAS Principles

HATEOAS (Hypermedia as the Engine of Application State) lets clients navigate APIs via links. The entry point provides initial links; subsequent actions are discovered from responses. This decouples clients from URL structures, enabling API evolution. HAL is one of several hypermedia formats (also Siren, Collection+JSON). The approach improves discoverability and self-documentation at the cost of larger responses.

discoverability
Links in responses
no hardcoded URLs
evolution
API can change URLs
clients follow links
tradeoff
Larger responses
more navigation

Outils associés

参考链接