Stackbook Logo
distribution-communicationestablished · medium operational burden

Hypermedia (HATEOAS)

Also known as: hateoas, hypermedia-api, hypermedia-controls

Intent

Drive client navigation and available actions through links embedded in server responses rather than hard-coded URLs.

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.

Forces

  • •Servers want freedom to change URL layout
  • •Allowed actions depend on resource state
  • •Clients should not duplicate workflow rules
  • •Extra payload and client sophistication have costs

Solution

Overview

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.

How it works

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.

Pitfalls

  • Treating links as decoration while clients still build URLs, which gives the cost without the benefit.
  • Emitting links regardless of authorisation, leading to 403 surprises.
  • Undocumented or unstable relation names. Relations are the contract; version them.
  • Chatty navigation requiring many hops; embed related resources where needed.
  • Adopting it for internal services where the coupling is acceptable anyway.

Key takeaways

  • Links express what the client can do next, based on current state.
  • Clients depend on relation names and media types, not URL shapes.
  • Worth the cost for long-lived, widely consumed APIs.
  • Keep link generation centralised and permission-aware.

✓ When to Use

  • •Long-lived public APIs with many third-party clients
  • •Workflows where allowed actions depend on state
  • •APIs expected to reorganise URLs over time

✗ When Not to Use

  • •Internal APIs with tightly coupled, co-deployed clients
  • •Simple CRUD with stable endpoints
  • •Teams without client support for link following

Pros

  • +Server can change URLs without breaking clients
  • +State-dependent actions discoverable
  • +Pagination and navigation come from the server

Cons

  • −Larger payloads
  • −Clients rarely implement link following fully
  • −Relation semantics still need documentation

Cost Profile

Infrastructure

Low - extra response fields

Operational

Medium - consistent link generation and docs

Cognitive

High - unfamiliar to many teams

Failure Modes

  • Clients ignore links and hard-code URLs anyway

  • Links offered for actions the caller lacks permission for

  • Link relation names change without versioning

Real-World Examples

Alternatives

    Related Patterns

      Competency Domains

      distribution communicationeconomics evolution