liveBook · Manning

Output

As explained in The Design of Web APIs, Second Edition

Output data is information produced by an API operation and returned as part of its result.

Operation output is the data an API returns as part of an operation’s result. Design it alongside the HTTP response: the status code tells consumers what happened, while response headers and bodies carry the information they need next. For a product search, that may be product information—or an empty list when nothing matches. section 4.1.2 section 4.6.2

Choose output according to what the consumer must do next:

  • After creating a product with POST, return its representation or a reference that lets the consumer retrieve it. A 201 Created response includes the new resource’s URL in a Location header, even if it has no body. section 4.6.2
  • After modifying a product, a 200 OK response can include the updated product; 204 No Content instead has no response data. Error statuses often need error information as well as the status code. section 4.6.2

Once the location is chosen, describe the output in OpenAPI. Response bodies and response headers have different places in the operation description, but their data can be specified with JSON Schema. This also makes an intentionally bodyless response distinct from one whose body was simply left undocumented. section 6.8 section 7.5

Listing 5.1 Sample response for the “Read movie information” operation
{
  "id": "ZFqoFq",
  "title": "Ghost In The Shell",
  "releaseYear": "1995",
  "duration": "83",
  "director": "Mamoru Oshii",
  "music": "Kenji Kawai",
  "language": "ja"
}

Use this movie-information response as a concrete output-design check: inspect each property and its JSON value before deciding whether the response data is modeled as intended. section 5.8

Keep output useful within its operation. Search filters should match the names and types of returned properties: a transaction category filter is easier to discover and use when transactions include category. A query parameter can also adjust returned values—for example, requesting a bank balance in EUR instead of the default USD—but should not drastically change the response structure or switch resources. In a car-rental flow, returned cars should include the information needed to choose one. section 9.6.1 section 9.7.3 section 10.1.4

Treat output as a consumer-facing contract when changing an API. Removing an expected property, changing its type, or adding an unexpected enum value can break consumers; the same caution applies to error bodies and response headers. Add or adjust data only within the limits of the existing response contract. section 15.2.1

Before publishing an operation, check:

How The Design of Web APIs, Second Edition covers it

How deep it goes
Works through response locations, bodyless and empty results, schema descriptions, and compatibility; defers detailed error handling.
Examples
Uses product creation and search results alongside movie JSON responses to illustrate output decisions.
What it assumes
Builds on resource models and HTTP response locations before describing operation output with schemas.
What you can do after
Practice/perform it by choosing response locations, describing output in OpenAPI, and checking changes for consumer compatibility.
How it connects
Connects response bodies and headers to OpenAPI and JSON Schema descriptions.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Design of Web APIs, Second Edition. The section links point to the parts of the book it draws on.