Problem
Clients that hard-code URL structures and state-dependent rules break whenever the server reorganises endpoints or workflows. Business rules about which actions are allowed get duplicated in every client.
Also known as: hateoas, hypermedia-api, hypermedia-controls
Drive client navigation and available actions through links embedded in server responses rather than hard-coded URLs.
Clients that hard-code URL structures and state-dependent rules break whenever the server reorganises endpoints or workflows. Business rules about which actions are allowed get duplicated in every client.
Hypermedia as the Engine of Application State (HATEOAS) is the top level of the REST maturity model. Responses carry the links a client can follow next, so the server, not the client, controls navigation and which operations are currently available.
A resource representation includes a links section keyed by relation name. Here is an order in HAL style.
GET /orders/42
{
"id": 42,
"status": "PENDING",
"_links": {
"self": { "href": "/orders/42" },
"pay": { "href": "/orders/42/payment" },
"cancel": { "href": "/orders/42" , "method": "DELETE" }
}
}
After payment the status becomes PAID and the pay link disappears while a refund link may appear. A client checks for the pay relation instead of re-implementing the rule that only pending orders can be paid. Paginated collections expose next and prev links, so clients never compute offsets.
Low - extra response fields
Medium - consistent link generation and docs
High - unfamiliar to many teams
Clients ignore links and hard-code URLs anyway
Links offered for actions the caller lacks permission for
Link relation names change without versioning