Practical guides

Document and test an API from its use cases

A useful API lets another team understand what it can request and what it will receive. Its contract should be testable, versioned and consistent with the operating service.

Go to the method

An API with a contract

Choose tasks before addresses

List uses such as finding a product, reading availability, updating a record or tracking processing. Define authorised people and systems for each operation. A public read API and an administrative API have different access requirements.

Prepare a request and response example for each essential task using synthetic values and explained fields. Distinguish stable identifiers, labels, units and dates. Define missing data instead of substituting plausible values for unknown information.

Describe an explicit contract

OpenAPI provides a language-independent description format for HTTP APIs, covering operations, parameters, responses and models. Choose a version supported by your tools and retain the document with the project; the newest version is not automatically the right fit for every toolchain.

Document usage limits, pagination, filters, ordering, errors and empty responses. Do not treat CORS as proof of authorisation. Review operation and object-level access controls with the technical team.

Test boundaries and permissions

Try an existing object, a missing object, an invalid parameter and a list longer than one page. Check the next page for losses or repeats within the chosen update model. State limitations that the API cannot guarantee.

Use test accounts with different permissions. Attempt reads and changes outside permitted scope using synthetic data. Record expected statuses and useful messages without exposing internal traces or configuration secrets.

Plan change and support

Distinguish an added field from a removed field or a changed meaning. Identify consumers before an incompatible change. Explain the transition period and how to detect integrations still using the earlier contract.

Deliver an executable example for a test environment, a test matrix and a technical contact. Relate observed errors to documented examples after release. Documentation limited to the ideal case leaves integrators without guidance for refusals and interruptions.

Primary documentation : OpenAPI Initiative — Specification.

Acceptance matrix to adapt to your project

These proposed checks use synthetic cases. Decide the required behaviour with the team, record the result and assign unresolved gaps before release.

Test cases, expected outcomes and useful evidence
CaseExpected outcomeEvidence to retain
Present and absent resourcesEach outcome matches the documented status and response model.Request, response and corresponding contract example captured from the test environment.
Out-of-range parameterThe refusal is understandable and exposes no internal stack trace.Public message and result retained in the acceptance matrix.
Two permission levelsA forbidden resource remains inaccessible even with a known identifier.Compared results using two synthetic accounts with explicitly different permissions.
Pagination and changed filterToken handling and journey restart behaviour are defined.Ordering, returned identifiers and rules applying when the filter changes.

Frequently asked questions

Is generated documentation enough to test an API?

It helps read a contract, but permissions, missing data, errors, lists and changes still require testing. Compare examples with actual test-environment responses.

Does CORS replace access permissions?

No. Cross-origin rules do not replace the service’s operation and object permissions. Describe those permissions and test server-side enforcement with test accounts.