📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

What is HATEOAS, and what are the levels of the Richardson maturity model? Walk through levels 0 to 3 with examples, explain what hypermedia buys a client, whether anyone really uses it in production, and what pragmatic stance you would take for a .NET API.

Hypermedia as the engine of application state and the Richardson maturity model levels 0-3, with examples, the real benefits and costs of hypermedia, where it is used (HAL, JSON:API, Siren, Microsoft Graph nextLink), and a pragmatic stance for ASP.NET Core APIs.

Mid-Level Theory Intermediate api-design hateoas hypermedia rest richardson-maturity-model web-api

🎯 Key points

  • Richardson model (Leonard Richardson, popularised by Martin Fowler 2010): level 0 single endpoint RPC, 1 resources, 2 HTTP verbs + status codes, 3 hypermedia controls
  • Level 0: one URI, one method (usually POST), the operation named in the body (SOAP, XML-RPC, JSON-RPC); level 2: GET/PUT/DELETE /orders/{id} with 200/201/404
  • HATEOAS: responses carry links for the next valid actions; the client follows links instead of building URLs
  • Benefits: server-driven workflows (omit 'cancel' link when not allowed), URL changes without breaking clients, workflow changes without client releases
  • Costs: richer media types (HAL, JSON:API, Siren), larger payloads, smarter clients, little tooling in .NET
  • Widely used partial hypermedia: pagination links (next/prev, @odata.nextLink), Location headers, Link header (RFC 8288)
  • Pragmatic stance: level 2 + OpenAPI, with links where they remove client logic (paging, async operation status, allowed actions); links never replace server-side enforcement

⏱ 30-second answer

The Richardson maturity model grades HTTP APIs: level 0 is one endpoint doing RPC (everything POSTed to /api), level 1 adds resources (/orders/42), level 2 uses HTTP methods and status codes properly, and level 3 adds hypermedia controls (HATEOAS): responses include links describing what the client can do next.

Hypermedia lets the server drive workflows (no cancel link once an order ships) and move URLs without breaking clients. In practice most production APIs are level 2 plus OpenAPI, with targeted hypermedia where it clearly removes client logic: next links for paging, Location for created resources and status URLs for long-running operations. Full HATEOAS costs richer media types and smarter clients, which few teams get a return on.

🗣 Full answer (senior)

How I would answer this in an interview

"The Richardson maturity model, from Leonard Richardson and made popular by Martin Fowler's 2010 article, is a way of grading how much of HTTP and REST an API actually uses. Level 0 is a single endpoint, say POST /api, with the operation in the body, like SOAP or JSON-RPC: HTTP is just a tunnel. Level 1 introduces resources, so you have /orders/42 and /customers/7, but you might still POST to everything. Level 2 uses the HTTP methods and status codes for their meaning: GET to read, PUT to replace, DELETE to remove, 201 with a Location, 404, 409 and so on. Level 3 adds hypermedia, which is HATEOAS: each response carries links for the actions available from this state, and the client navigates by following them rather than constructing URLs.

The value of level 3 is that the server owns the workflow. An order in Pending comes back with pay and cancel links; once it's Shipped, the cancel link just isn't there, so the mobile app doesn't need its own copy of the business rule. It also lets the server change URLs. The honest answer to 'does anyone use it' is: fully, rarely. Most APIs I've worked on, and most public ones, are level 2 with an OpenAPI document. But partial hypermedia is everywhere: Microsoft Graph's @odata.nextLink, GitHub's Link header for pagination, and Operation-Location in Azure long-running operations.

The mistake I see is either treating level 3 as the goal for its own sake, or dismissing links entirely and making clients build paging URLs and status-polling URLs by hand. My stance for an ASP.NET Core API is level 2 as the baseline, plus links where they remove logic from clients: paging, the status resource of a long-running operation, and allowed actions on a stateful resource. I'm pragmatic: hypermedia where it earns its keep."


The four levels

Level Name Example What you gain
0 The swamp of POX POST /api {"action":"getOrder","id":42} Nothing from HTTP
1 Resources POST /orders/42/get Addressable things
2 HTTP verbs GET /orders/42 -> 200; DELETE -> 204 Caching, safe retries, standard errors
3 Hypermedia controls Response includes links.cancel.href Server-driven workflow, evolvable URLs

Hypermedia formats

Format Shape Where you see it
HAL (application/hal+json) _links, _embedded Spring, some public APIs
JSON:API links, relationships Ember ecosystem, some SaaS
Siren actions with method and fields Rare, richest
OData annotations @odata.nextLink, @odata.id Microsoft Graph, Dynamics
Link header (RFC 8288) Link: <...?page=3>; rel="next" GitHub API

Production example

A [loan application] API used state-dependent links (submit, withdraw, upload-documents). When the business added a new ["referred to underwriter"] state, the web and mobile clients needed no release: they simply rendered the actions the API returned. Previously, [each workflow change needed coordinated releases across three apps].

🔍 What the interviewer is checking

Checks that the candidate knows the maturity levels accurately and has a reasoned, practical view on hypermedia rather than a dogmatic one.

Green flags

  • Describes levels 0-3 with concrete examples
  • Explains state-dependent links and their benefit
  • Gives real examples of partial hypermedia (nextLink, Location, Link header)
  • Notes links don't replace server-side enforcement

Red flags

  • Can't name the levels or confuses level 1 and 2
  • Claims HATEOAS is required for every API, or is useless with no reasoning
  • Thinks hiding a link is a security control

📚 Learn in depth

1. Where the model comes from

Leonard Richardson presented the model at QCon 2008; Martin Fowler's 2010 article "Richardson Maturity Model: steps toward the glory of REST" made it famous. Fielding himself says only level 3 is REST; the model is a teaching tool, not a standard.

2. Level 0 to 2 in requests

Level 0:  POST /api            {"method":"cancelOrder","orderId":42}  -> 200 {"ok":false}
Level 1:  POST /orders/42      {"action":"cancel"}                    -> 200
Level 2:  POST /orders/42/cancellation                                -> 202 / 409 if already shipped
          GET  /orders/42                                             -> 200, Cache-Control, ETag

3. Level 3: state-dependent links

{
  "id": 42,
  "status": "Pending",
  "_links": {
    "self":   { "href": "/orders/42" },
    "pay":    { "href": "/orders/42/payments", "method": "POST" },
    "cancel": { "href": "/orders/42/cancellation", "method": "POST" }
  }
}

The client's logic becomes "show a Cancel button if there's a cancel link". The server still enforces the rule (it must return 409 if someone calls cancel anyway); the links just stop the client duplicating it.

4. Why it rarely goes all the way

  • Clients are usually written against documentation and generated SDKs (NSwag, Kiota), which hard-code URLs anyway.
  • Link relation names still need documentation; the client must know what cancel means.
  • Payloads grow, and every endpoint must compute allowed actions, which may need extra queries.
  • .NET has no first-class HAL support in ASP.NET Core; you build link DTOs yourself with LinkGenerator.

5. Where partial hypermedia pays off

Paging:            {"items":[...], "nextLink":"/orders?cursor=eyJ..."}
Created resource:  201 Created, Location: /orders/42
Long-running op:   202 Accepted, Location: /operations/abc  (poll it)
Allowed actions:   "actions": ["cancel","pay"]  or links

Opaque nextLink cursors are the best example: the client can't construct them, so the server can change the paging strategy freely.

6. Generating links in ASP.NET Core

Use LinkGenerator.GetPathByName("GetOrder", new { id }) with named endpoints (.WithName("GetOrder")), so links follow route changes. Behind a proxy, configure forwarded headers before generating absolute URIs.

Try it yourself

  1. Classify three APIs you use (your own, GitHub, Microsoft Graph) by Richardson level.
  2. Add a links object to an order DTO with LinkGenerator, including a cancel link only for pending orders.
  3. Rename the cancel route and confirm the generated links follow it.
  4. Implement cursor paging that returns nextLink, then change the cursor format and check the client still works.

💻 Code

State-dependent links built with LinkGenerator, so clients render actions the server allows and URLs follow route changes.

// Program.cs (.NET 10)
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

var orders = new Dictionary<int, Order> { [42] = new(42, OrderStatus.Pending), [43] = new(43, OrderStatus.Shipped) };

app.MapGet("/orders/{id:int}", (int id, LinkGenerator links, HttpContext ctx) =>
{
    if (!orders.TryGetValue(id, out var order)) return Results.NotFound();

    var actions = new Dictionary<string, Link>
    {
        ["self"] = new(links.GetPathByName(ctx, "GetOrder", new { id })!, "GET"),
    };
    // The server decides which transitions are valid now; the client only checks for the link.
    if (order.Status == OrderStatus.Pending)
    {
        actions["cancel"] = new(links.GetPathByName(ctx, "CancelOrder", new { id })!, "POST");
        actions["pay"] = new(links.GetPathByName(ctx, "PayOrder", new { id })!, "POST");
    }
    return Results.Ok(new OrderResource(order.Id, order.Status.ToString(), actions));
}).WithName("GetOrder");

app.MapPost("/orders/{id:int}/cancellation", (int id) =>
    orders.TryGetValue(id, out var o) && o.Status == OrderStatus.Pending
        ? Results.Accepted()
        : Results.Problem(statusCode: 409, title: "Order can no longer be cancelled")) // still enforced server-side
   .WithName("CancelOrder");

app.MapPost("/orders/{id:int}/payments", (int id) => Results.Accepted()).WithName("PayOrder");

app.Run();

public enum OrderStatus { Pending, Shipped }
public sealed record Order(int Id, OrderStatus Status);
public sealed record Link(string Href, string Method);
public sealed record OrderResource(int Id, string Status, IReadOnlyDictionary<string, Link> Links);
{ "id": 42, "status": "Pending",
  "links": { "self": { "href": "/orders/42", "method": "GET" },
             "cancel": { "href": "/orders/42/cancellation", "method": "POST" },
             "pay": { "href": "/orders/42/payments", "method": "POST" } } }

⚠ Common mistakes

  • Mistake: Calling a level 2 API "fully RESTful". Why it is wrong: By Fielding's definition, REST requires hypermedia. Instead: Say "level 2, pragmatic REST" and explain why.
  • Mistake: Adding only static links (a self link and nothing else) and calling the API hypermedia-driven. Why it is wrong: Links that never change with state remove no client logic, so clients still hard-code the workflow. Instead: Put the effort into links that encode state (allowed actions) or opacity (paging cursors, operation status URLs); self links are fine as a convenience, not as the point.
  • Mistake: Dismissing hypermedia entirely and hard-coding every URL and rule in clients. Why it is wrong: Every workflow or URL change then needs coordinated client releases, which is painful with mobile apps users don't update. Instead: Use targeted links for the transitions that change most often.
  • Mistake: Relying on links for authorisation. Why it is wrong: Hiding the cancel link doesn't stop a client calling the URL. Instead: Enforce every rule on the server and return 403 or 409; links mirror the rules, they don't replace them.
  • Mistake: Hard-coding absolute URLs in links. Why it is wrong: They break behind proxies and across environments. Instead: Use LinkGenerator with named endpoints and forwarded headers.
  • Mistake: Making clients build paging or polling URLs. Why it is wrong: It locks the server into one URL scheme. Instead: Return nextLink and Location/status URLs.
  • Mistake: Choosing full level 3 for an internal API with one SPA client. Why it is wrong: The cost outweighs the benefit when you ship both sides together. Instead: Level 2 plus OpenAPI, with targeted links.

🏛 Senior insight: trade-offs

The senior answer avoids both dogma and dismissal. Hypermedia is a tool for decoupling client releases from server workflow changes; it pays off when many independently released clients (mobile apps that users don't update, partner integrations) consume a workflow that changes. For an internal API deployed with its only client, level 2 plus generated SDKs is cheaper and just as evolvable.

I'd measure the case for it: how many client releases were forced by server-side workflow changes last year, and how often clients broke because they built URLs themselves.

Option When it fits Cost When not
Level 2 + OpenAPI Most internal and partner APIs Clients hard-code URLs and rules Many uncontrolled clients with changing workflows
Targeted links (paging, operations, actions) Almost any API Small DTO and link-generation work Never really wrong
Full HATEOAS (HAL/Siren) Long-lived public APIs, workflow-heavy domains Media types, client complexity, payload size Single SPA client released with the API

🔗 Follow-ups the interviewer may ask

  1. When: Candidate mentions Fielding or the uniform interface Why: Checks the underlying REST constraints, especially the uniform interface
    How to answer

    REST (Representational State Transfer) is an architectural style Roy Fielding described in 2000, not a protocol. It is defined by six constraints: client-server, stateless requests, cacheable responses, a uniform interface, a layered system, and optional code on demand. The uniform interface is the heart of it: resources identified by URIs, changed through representations (JSON, XML), self-descriptive messages (methods, status codes, media types) and hypermedia links that drive the client (HATEOAS).

    In practice, when a team says "RESTful" they usually mean resource-oriented URLs, correct HTTP methods and status codes, and JSON, but no hypermedia. That is fine for most internal and partner APIs; the trade-off is that clients hard-code URLs and workflows instead of discovering them.

  2. When: Candidate mentions discoverability or allowed actions Why: Checks other discovery mechanisms such as OPTIONS and the Allow header
    How to answer

    HEAD is GET without the body: same status code and headers (Content-Length, ETag, Last-Modified), so clients can check that a resource exists, how big it is or whether it changed, without downloading it. It is safe, idempotent and cacheable.

    OPTIONS asks what the server supports for a URI; the answer is the Allow header. Its main real-world use is the CORS preflight: browsers send OPTIONS with Origin and Access-Control-Request-Method before non-simple cross-origin calls, and ASP.NET Core's CORS middleware answers it.

    ASP.NET Core handles preflight and 405 Allow headers for you, but Minimal APIs don't map HEAD automatically. The trade-off: HEAD support is cheap to add but must not cost as much as the GET it replaces.

🛠 Real-world problems: how you handle them

Workflow change forced a coordinated release across three apps
Situation
A [loan application] API served a web app, an iOS app and an Android app. Clients hard-coded which actions were allowed in each application state. The business added a new ["referred"] state; [~30%] of mobile users were on app versions more than two months old.
Signals
After the server release, old app versions showed a Withdraw button for referred applications; calls returned 409 and Application Insights showed a spike of [~1,200] 409 failures per day on `POST /applications/{id}/withdrawal`. App-store reviews complained about "error when withdrawing".
Investigation
Application Insights `requests` filtered by result code 409 and grouped by the `User-Agent` app version showed the errors came from versions before [x.y]. Reviewing client code found a switch statement duplicating the server's state machine. The OpenAPI diff showed no contract change, which is why contract tests passed.
Resolution
Immediate: the server returned a clear ProblemDetails message for the 409 so old apps showed a sensible error. Long term: the application resource gained an `actions` collection (links for withdraw, submit, upload-documents) computed from the server state machine, and clients were changed to render buttons only for returned actions.
Prevention
An ADR made allowed actions part of the resource contract; integration tests assert the actions for each state; a dashboard tracks 409s per endpoint and app version; new workflow states are added server-side only.

How to tell it (STAR)

**S:** At [company], our loan application API had three clients that each hard-coded which buttons to show for each application state, and [a third] of mobile users ran old versions. **T:** When the business added a referred state, old apps started offering actions the server rejected, and I was asked to stop this happening with every workflow change. **A:** I traced the 409 spike in Application Insights to old app versions, then proposed returning the allowed actions as links on the resource, computed from the server's state machine. I wrote the ADR, implemented the links with `LinkGenerator` and worked with the mobile leads so the apps render only what the API returns. **R:** The next two workflow changes shipped server-only with zero client releases, and 409s on workflow endpoints dropped by [~95%].

↩ Usually asked after

More in REST

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me