API Documentation Guide Cheat Sheet

API documentation best practices — endpoint descriptions, request/response examples, authentication docs, OpenAPI/Swagger, SDK documentation, and developer experi.

Last Updated: May 1, 2025

API Doc Structure

ItemDescription
1. OverviewWhat the API does, base URL, authentication method, rate limits, API version. 2-minute read.
2. AuthenticationHow to get API keys, OAuth flow, token format, environment variables for storing keys.
3. QuickstartCurl command that works immediately after copy-paste. 'Your first API call in 30 seconds.'
4. ConceptsKey domain concepts: 'In our API, a Workspace contains Projects, which contain Tasks.'
5. EndpointsMethod, path, description, parameters, request example, response example, error responses.
6. GuidesCommon workflows: 'How to upload a file', 'How to set up webhooks', pagination, error handling.
7. SDKs / LibrariesInstallation, instantiation, key methods with examples. Link to source repos.

Endpoint Documentation Pattern

ItemDescription
Method + Path`GET /api/v1/users/{id}` — HTTP method, full path, path parameters in braces
Description1-2 sentences describing what it does. 'Returns a user object by ID.'
Path ParametersTable: Name, Type, Required, Description. `id: string, required, The user UUID`
Query ParametersTable: Name, Type, Required, Default, Description. `limit: integer, optional, 20, Max results`
Request BodyJSON example with all possible fields. Indicate required vs optional. Include field descriptions.
ResponseJSON example for 200, plus common error responses (400, 401, 404, 429, 500).

OpenAPI / Swagger Tips

ItemDescription
Use OpenAPI 3.1Latest version. Better JSON Schema support, webhook support, better examples.
description FieldsEvery endpoint, parameter, and schema property needs a description. Auto-generated docs use these.
examples > exampleThe `examples` field (plural) supports multiple named examples. Better than single `example`.
$ref for ReuseExtract common schemas: `$ref: '#/components/schemas/User'`. Don't duplicate schema definitions.
Redoc / Swagger UIRender OpenAPI specs as beautiful docs. Redoc = cleaner, Swagger UI = interactive 'Try it'.
ValidationUse spectral (Stoplight) to lint your OpenAPI spec. Catch missing descriptions, inconsistent naming.

Developer Experience

ItemDescription
Copy-Paste ReadyEvery code example should run without modification. Use placeholder values that look real.
Error MessagesReturn actionable errors: 'API key invalid. Get one at https://...' not 'Unauthorized.'
ChangelogPublic changelog with dates. Breaking changes in BOLD at top. Migration guides for version bumps.
Rate Limit HeadersReturn X-RateLimit-Remaining headers. Developer can self-police instead of hitting 429s.
SDK GenerationUse openapi-generator to create SDKs in 20+ languages from your OpenAPI spec. Keep them in sync.
Pro Tip: The 'Getting Started' section is the most important page in your API docs. A developer should make their first successful API call within 5 minutes. If they can't, you've already lost 50% of potential users.