How to write API documentation in Markdown
Write REST API documentation in Markdown with a fixed endpoint template, parameter tables, curl examples and error codes, and pair it with an OpenAPI file.

To write API documentation in Markdown, give every endpoint the same page structure: a heading with the HTTP method and path, one sentence on what it does, a table of parameters, a request example you can paste into a terminal, a real response, and the errors it can return. Put authentication, pagination and error formats on their own pages so each endpoint page stays short. If you also keep an OpenAPI file, let it own the exact schema and let Markdown carry the explanations, guides and examples that a schema cannot.
Below is a template you can copy, what goes on the pages around it, and how Markdown and OpenAPI fit together.
What should an API reference page include?
An API reference page should let a developer make a successful call without asking anyone. In practice that means seven parts, always in the same order, so readers know where to look on every page.
| Part | Answers | Format |
|---|---|---|
| Method and path | What do I call? | ## heading, e.g. POST /v1/invoices |
| Summary | What does it do? | One sentence |
| Authentication | What permission do I need? | One line, linking to the auth page |
| Parameters | What can I send? | Table: name, in, type, required, description |
| Request example | What does a call look like? | bash code block with curl |
| Response example | What comes back? | json code block, real data |
| Errors | What can go wrong? | Table: status, code, meaning |
Is there an endpoint template you can copy?
Yes. One file per resource, one ## section per endpoint, works for most REST APIs.
# Invoices
Create, list and void invoices for a customer.
## POST /v1/invoices
Creates a draft invoice for a customer.
**Requires:** an API key with the `invoices:write` scope.
See [Authentication](authentication.md).
### Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `customer_id` | body | string | Yes | ID of the customer to bill |
| `currency` | body | string | Yes | Three-letter ISO 4217 code, e.g. `eur` |
| `due_date` | body | string | No | ISO 8601 date. Defaults to 30 days from today |
| `Idempotency-Key` | header | string | No | Makes retries safe. See [Retries](retries.md) |
### Request
```bash
curl -X POST https://api.example.com/v1/invoices \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{"customer_id": "cus_8f2k", "currency": "eur"}'
```
### Response
`201 Created`
```json
{
"id": "inv_31kd",
"customer_id": "cus_8f2k",
"currency": "eur",
"status": "draft",
"due_date": "2026-12-26"
}
```
### Errors
| Status | Code | Meaning |
|---|---|---|
| 400 | `invalid_currency` | `currency` is not a supported ISO 4217 code |
| 404 | `customer_not_found` | No customer with that ID in this account |
| 409 | `idempotency_conflict` | Same key was used with a different body |
The outer four backticks only let the template display here with its code blocks intact. Your file starts at # Invoices. Syntax for the tables and fences is on the tables and code blocks pages.
What pages does an API need besides the reference?
Most questions developers ask are not about a single endpoint. Write these pages once and link to them from every endpoint instead of repeating them:
- Quickstart. From zero to one successful call in five minutes: get a key, make a request, see the result.
- Authentication. How to get credentials, where to send them, how scopes work, and what a failed auth response looks like.
- Errors. The shape of every error body, with the full list of codes in one table.
- Pagination. Cursor or page parameters, the response fields that point to the next page, and a loop example.
- Rate limits. The limits, the headers that report them, and what to do on a
429. - Versioning and changelog. How versions are named, how long old ones live, and what changed when. A Markdown changelog works for this.
- Webhooks. Event names, payload examples and how to verify a signature, if the API sends them.
A folder that holds all of it:
api-docs/
index.md
quickstart.md
authentication.md
errors.md
pagination.md
rate-limits.md
changelog.md
reference/
customers.md
invoices.md
payments.md
openapi.yaml
How do you write examples developers can trust?
Write examples from real requests, not from memory. An example that returns a field the API no longer sends costs a developer more time than no example.
- Use runnable commands. curl is readable in every language community. Put secrets in environment variables, as
$API_KEYabove, so nobody pastes a real key into a doc. - Show a real response. Run the request against a test account and paste the output, then replace private values with obvious placeholders such as
cus_8f2k. - Keep IDs consistent. If the request uses
cus_8f2k, the response should too. - Tag every block.
bashfor commands,jsonfor bodies,httpfor raw requests. Highlighting makes long payloads scannable, and linters can enforce it. - Test examples in CI. Even a script that runs every curl block against a sandbox and checks for a
2xxcatches most rot.
Should you use OpenAPI or Markdown?
Use both, for different jobs. An OpenAPI file describes the exact contract (paths, parameters, schemas, status codes) in a form tools can read, so it can generate reference pages, client libraries, mock servers and request validation. Markdown carries what a schema cannot: guides, concepts, migration notes and the reasoning behind a design.
They also overlap on purpose. The OpenAPI Specification states that "CommonMark syntax MAY be used for rich text representation" in its description fields (checked November 2026), so the longer explanations inside the spec are Markdown too:
paths:
/v1/invoices:
post:
summary: Create an invoice
description: |
Creates a **draft** invoice. Drafts can be edited until they are
finalized. See [Invoice lifecycle](https://docs.example.com/lifecycle).
responses:
"201":
description: The created invoice.
| Hand-written Markdown | OpenAPI-generated reference | |
|---|---|---|
| Setup | None | Write and maintain the spec |
| Accuracy | Depends on discipline | Matches the spec, which can be validated |
| Guides and concepts | Natural fit | Possible in descriptions, awkward at length |
| Client code and mocks | No | Yes, through generators |
| Fits | Small APIs, internal APIs | Public APIs, many endpoints |
A common split: OpenAPI for the reference, rendered by a tool such as Redoc or Swagger UI, and Markdown pages for the quickstart, guides and changelog, all in one docs site. With Redocly's CLI, npx @redocly/cli lint openapi.yaml checks the spec and npx @redocly/cli build-docs openapi.yaml writes a single HTML reference page.
Where should API docs live?
Keep them in the same repository as the API, so a pull request that changes an endpoint also changes its documentation and reviewers see both. Lint the Markdown and validate the OpenAPI file in CI. That workflow is described in docs as code.
A review checklist for API changes:
- New or changed parameters appear in the table with type and default
- The request example runs against the sandbox
- The response example matches the current output
- New error codes are on the endpoint page and the errors page
- Breaking changes are in the changelog
Writing API docs in Noteline
Noteline, which we make, edits API documentation as plain Markdown files in your repository. Parameter and error tables can be edited cell by cell, and bash, json and yaml code blocks are highlighted as you type. Markdown Source (Cmd+Shift+M on a Mac, Ctrl+Shift+M on Windows and Linux) shows the raw table pipes when you want to check them. It does not validate or render OpenAPI files, so use your API tooling for the spec itself. For readers who need a file instead of a site, the desktop app exports a page to Word or PDF.