Skip to main content
Documentation

How to Write API Documentation in Markdown

A practical guide to structuring and writing API reference documentation using markdown. Covers endpoints, parameters, request/response examples.

MarkGenie Team
10 min read
Free to read

In this article

📖 Comprehensive guide
⏱️ 10 min read
🎯 Documentation
Advertisement

How to Write API Documentation in Markdown

Good API documentation is the difference between developers adopting your API in an afternoon and abandoning it in frustration. Markdown is ideal — readable as plain text, renders beautifully, and version-controls cleanly alongside your code.

Core Structure

Every API reference doc needs:

  1. Overview — what the API does, base URL, authentication
  2. Authentication — how to obtain and use credentials
  3. Endpoints — one section per endpoint
  4. Error Reference — every error code with its meaning
  5. Rate Limits — throttling rules and headers

Documenting an Endpoint

markdown
## GET /users/{id}

Retrieve a single user by their ID.

**Authentication:** Bearer token required

### Path Parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| id | string | Yes | The user's unique identifier |

### Query Parameters

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| include | string | — | Relations to include (e.g. `posts,followers`) |

### Request Example

```bash
curl -X GET https://api.example.com/users/usr_123 \
  -H "Authorization: Bearer YOUR_TOKEN"

Response (200 OK)

json
{
  "id": "usr_123",
  "name": "Jane Doe",
  "email": "[email protected]",
  "created_at": "2024-01-15T10:30:00Z"
}

Error Responses

CodeDescription
401Missing or invalid authentication token
404User not found

## Documenting Authentication

```markdown
## Authentication

Include your API key in every request:

```bash
Authorization: Bearer sk_live_xxxxxxxxxxxxxxxxxxxx

Security: Never expose API keys in client-side code or commit them to version control. Use environment variables.


## Error Reference Section

```markdown
## Error Reference

All errors follow this format:

```json
{
  "error": {
    "code": "user_not_found",
    "message": "No user with ID usr_123 exists"
  }
}
HTTP StatusError CodeDescription
400invalid_requestRequest body failed validation
401unauthorizedMissing or invalid API key
404not_foundResource doesn't exist
429rate_limitedToo many requests
500server_errorInternal error

## Rate Limits

```markdown
## Rate Limits

| Plan | Requests/minute | Requests/day |
|------|----------------|--------------|
| Free | 60 | 1,000 |
| Pro | 600 | 50,000 |

Rate limit headers in every response:

X-RateLimit-Limit: 60 X-RateLimit-Remaining: 42 X-RateLimit-Reset: 1705312800

Best Practices

Use Real Examples

Always use realistic values — not string, 123, or foo. Readers copy-paste examples.

Document Every Field

Even optional ones. Undocumented fields become support tickets.

Note Deprecations

markdown
> **Deprecated:** The `username` field is deprecated as of v2.1. Use `handle` instead. Will be removed in v3.0 (2026-Q3).

Link from Errors to Docs

Add a docs URL in error responses pointing to the relevant docs page.

Complementary Tools

  • OpenAPI/Swagger — machine-readable spec; generate markdown with widdershins
  • Redoc / Stoplight — render OpenAPI specs beautifully
  • Docusaurus — static site with excellent code block support

Draft your API docs in MarkGenie's editor to preview tables and code blocks before committing.

Ready to try it yourself?

Put these tips into practice with MarkGenie's live markdown editor

Was this article helpful? Let us know!