liveBook · Manning

Default value

As explained in The Design of Web APIs, Second Edition

A default value is a parameter value applied when an API consumer does not provide that parameter.

A default value supplies a parameter when an API consumer omits it. Defaults reduce request complexity, but only when the implementation can determine a safe value without losing accuracy. section 9.4.4

Money transfer defaults

A transfer needs source, destination, and amount. The implementation can infer an immediate transfer when no date or frequency is supplied, use the source account’s currency when currency is omitted, start a recurring transfer today, and continue it when endDate is absent. Do not default values the server cannot know accurately, such as a payment transaction’s execution timestamp. section 9.4.4

Use defaults deliberately across request design and consumer-facing documentation:

  • Keep parameters optional when the implementation can infer them reliably; avoid making semantically important data optional merely to shorten requests. section 9.4.4
  • Declare static defaults with JSON Schema’s default keyword; for example, an omitted limit can default to 100. section 19.3.2
  • Return effective defaults in list metadata so consumers know the applied page size, sort order, and other parameters. section 9.6.7
  • Keep filters optional and do not assume they require defaults; an unfiltered account-transaction request can return all transactions. section 9.6.4
Figure 9.7 We minimize money transfer inputs by determining data based on other data and using default data.
figure

Use the transfer-input diagram to compare explicitly supplied data, inferred transfer types, and server-provided defaults. section 9.4.4

How The Design of Web APIs, Second Edition covers it

How deep it goes
Defines server-inferred values and JSON Schema defaults, stopping short of detailed implementation mechanics.
Examples
Uses money transfers, currency, recurring dates, pagination limits, and transaction-list metadata as concrete examples.
What it assumes
Assumes basic API parameters and data schemas while teaching when omitted values can be inferred safely.
What you can do after
Apply it via API schemas and response metadata to reduce inputs and reveal the values actually used.
How it connects
Connects optional parameters with JSON Schema, pagination, sorting, filtering, response metadata, and interoperability.

Also explained in

Compare how 20 books explain default value →

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.