liveBook · Manning

API security

As explained in The Design of Web APIs, Second Edition

API security is the protection of an application programming interface, its operations, and the data and resources it exposes from unauthorized access or harmful use.

API security protects operations, data, and exposed resources from unauthorized access or harmful use. It limits what authorized consumers and end users can access while reducing privacy, financial, operational, and reputational harm. section 12.0 section 12.1

Treat security as a design constraint across capability identification, HTTP representations, data modeling, and OpenAPI documentation—not as a one-time implementation task. Revisit it whenever the API changes. section 12.2.1 section 12.2.2

Shopping API order retrieval

A website obtains an access token from an authorization server, then sends GET /orders with an Authorization header over HTTPS. The resource server validates the consumer, checks the order scope, identifies the end user from the token, and returns that user’s orders. section 12.1.1

Figure 12.1 The shopping website gets an access token to call the Shopping API to retrieve an end user’s orders. Based on the token, the Shopping API implementation verifies that the consumer has appropriate permissions before returning the user’s data.
figure

Use the call-flow diagram to follow authentication, secure transport, scope validation, and end-user data selection. section 12.1.1

Design decisions that reduce API security risk include:

  • Expose only necessary data and operations, and avoid revealing provider-side business logic or infrastructure details. section 1.2.3 section 12.2.2
  • Define clearly who can see or do what; partition access with scopes based on operations, resources, use cases, read/write actions, consumers, or end users. section 12.11 section 12.2.2
  • Protect integrity by conditioning updates on fresh data and preventing replay of element-creation requests. section 12.2.2 section 12.11
  • Document security requirements, scopes, and errors in OpenAPI; return 401 for token problems, 403 for fixable permissions, and 404 for non-fixable access failures. section 12.11
  • Review security-breaking changes deliberately: replacing API keys with mutual TLS may require a breaking change, while temporary coexistence can ease migration. section 15.3

Health and fitness data review

Before allowing every user to read every profile or workout, inspect fields such as phone numbers, email addresses, birth dates, and GPS coordinates. Decide which data and operations are necessary for the sharing use case and remove or restrict the rest. section 12.13

How The Design of Web APIs, Second Edition covers it

How deep it goes
Explains call-level transport, consumer authorization, scopes, end-user context, integrity, errors, and OpenAPI documentation.
Examples
Uses Shopping API orders, health profiles, workouts, GPS coordinates, scopes, conditional requests, and mutual TLS migration.
What it assumes
Assumes familiarity with API design and HTTP while introducing security mechanisms, scopes, sensitive data handling, and OpenAPI requirements.
What you can do after
Apply API security by limiting exposure, defining scopes, documenting controls, securing errors, and reviewing security-breaking modifications.
How it connects
Connects API security with access control, HTTPS, OAuth 2.0, OpenID Connect, OpenAPI, sensitive data, scopes, and data integrity.

Also explained in

Compare how 3 books explain API security →

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.