API Service README Template
Create a README for a REST API or backend service. Covers endpoint documentation, authentication, request/response examples, error codes, and deployment with Docker.
Detailed Explanation
Documenting an API Service
An API service README needs to communicate how to set up, run, and interact with the API. Developers reading it may be backend contributors, frontend developers consuming the API, or DevOps engineers deploying it.
Authentication Section
Document the authentication method upfront:
# Obtain a token
curl -X POST https://api.example.com/auth/login \
-H "Content-Type: application/json" \
-d '{"email": "user@example.com", "password": "secret"}'
# Use the token
curl https://api.example.com/v1/items \
-H "Authorization: Bearer eyJhbG..."
Endpoint Documentation Table
A concise endpoint table gives an overview of the entire API:
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| POST | /auth/login | Authenticate user | No |
| GET | /v1/items | List all items | Yes |
| POST | /v1/items | Create an item | Yes |
| GET | /v1/items/:id | Get item by ID | Yes |
| PUT | /v1/items/:id | Update an item | Yes |
| DELETE | /v1/items/:id | Delete an item | Yes |
Request/Response Examples
For each major endpoint, show a complete request and response:
# Create an item
curl -X POST https://api.example.com/v1/items \
-H "Authorization: Bearer TOKEN" \
-H "Content-Type: application/json" \
-d '{"name": "Widget", "price": 29.99}'
Response:
{
"id": "abc123",
"name": "Widget",
"price": 29.99,
"createdAt": "2024-01-15T10:30:00Z"
}
Error Codes
Document common error responses:
| Code | Description |
|---|---|
| 400 | Invalid request body |
| 401 | Missing or invalid token |
| 403 | Insufficient permissions |
| 404 | Resource not found |
| 429 | Rate limit exceeded |
Docker Deployment
Most API services benefit from Docker documentation:
docker build -t my-api .
docker run -p 3000:3000 --env-file .env my-api
Use Case
Documenting a REST API backend that frontend developers, mobile developers, and third-party integrators will consume, needing clear endpoint references and authentication instructions.