v2/examples/rest-api-simple/api-specification.md
Base URL: http://localhost:3000/api/v1
Content-Type: application/json
API Version: 1.0.0
interface Task {
id: number; // Auto-generated, unique
title: string; // Required, task title
description: string; // Optional, detailed description
completed: boolean; // Default: false
createdAt: string; // ISO 8601 timestamp
updatedAt: string; // ISO 8601 timestamp
}
interface ErrorResponse {
error: {
message: string; // Human-readable error message
status: number; // HTTP status code
timestamp: string; // ISO 8601 timestamp
}
}
Endpoint: GET /health
Description: Check if the API is running and healthy
Authentication: None
{
"status": "healthy",
"timestamp": "2024-01-15T10:30:00.000Z",
"uptime": 3600,
"version": "1.0.0"
}
Status Codes:
200 OK: Service is healthyEndpoint: GET /api/v1/tasks
Description: Retrieve all tasks
Authentication: None
| Parameter | Type | Required | Description |
|---|---|---|---|
| completed | boolean | No | Filter by completion status |
| limit | number | No | Number of results (default: 100) |
| offset | number | No | Pagination offset (default: 0) |
{
"tasks": [
{
"id": 1,
"title": "Complete API documentation",
"description": "Write comprehensive API docs",
"completed": false,
"createdAt": "2024-01-15T10:00:00.000Z",
"updatedAt": "2024-01-15T10:00:00.000Z"
}
],
"total": 1,
"limit": 100,
"offset": 0
}
Status Codes:
200 OK: SuccessEndpoint: GET /api/v1/tasks/:id
Description: Retrieve a specific task by ID
Authentication: None
| Parameter | Type | Required | Description |
|---|---|---|---|
| id | number | Yes | Task ID |
{
"id": 1,
"title": "Complete API documentation",
"description": "Write comprehensive API docs",
"completed": false,
"createdAt": "2024-01-15T10:00:00.000Z",
"updatedAt": "2024-01-15T10:00:00.000Z"
}
Status Codes:
200 OK: Success404 Not Found: Task not foundEndpoint: POST /api/v1/tasks
Description: Create a new task
Authentication: None
{
"title": "New task",
"description": "Task description (optional)",
"completed": false
}
title: Required, string, 1-255 charactersdescription: Optional, string, max 1000 characterscompleted: Optional, boolean, defaults to false{
"id": 2,
"title": "New task",
"description": "Task description",
"completed": false,
"createdAt": "2024-01-15T11:00:00.000Z",
"updatedAt": "2024-01-15T11:00:00.000Z"
}
Status Codes:
201 Created: Success400 Bad Request: Invalid inputEndpoint: PUT /api/v1/tasks/:id
Description: Update an existing task
Authentication: None
| Parameter | Type | Required | Description |
|---|---|---|---|
| id | number | Yes | Task ID |
{
"title": "Updated task title",
"description": "Updated description",
"completed": true
}
{
"id": 1,
"title": "Updated task title",
"description": "Updated description",
"completed": true,
"createdAt": "2024-01-15T10:00:00.000Z",
"updatedAt": "2024-01-15T12:00:00.000Z"
}
Status Codes:
200 OK: Success400 Bad Request: Invalid input404 Not Found: Task not foundEndpoint: DELETE /api/v1/tasks/:id
Description: Delete a task
Authentication: None
| Parameter | Type | Required | Description |
|---|---|---|---|
| id | number | Yes | Task ID |
{
"message": "Task deleted successfully",
"id": 1
}
Status Codes:
200 OK: Success404 Not Found: Task not found| Header | Required | Description |
|---|---|---|
| Content-Type | Yes (for POST/PUT) | Must be application/json |
| Accept | No | Preferred: application/json |
| Header | Description |
|---|---|
| Content-Type | Always application/json |
| X-Request-ID | Unique request identifier |
All errors follow a consistent format:
{
"error": {
"message": "Descriptive error message",
"status": 400,
"timestamp": "2024-01-15T12:00:00.000Z"
}
}
| Status Code | Description |
|---|---|
| 400 | Bad Request - Invalid input |
| 404 | Not Found - Resource doesn't exist |
| 500 | Internal Server Error |
No rate limiting implemented in the simple version.
Currently allows all origins (*) for development purposes.
curl -X POST http://localhost:3000/api/v1/tasks \
-H "Content-Type: application/json" \
-d '{
"title": "Learn REST APIs",
"description": "Build a simple REST API with Express"
}'
curl http://localhost:3000/api/v1/tasks
curl -X PUT http://localhost:3000/api/v1/tasks/1 \
-H "Content-Type: application/json" \
-d '{
"completed": true
}'
curl -X DELETE http://localhost:3000/api/v1/tasks/1
The API includes a comprehensive test suite using Jest and Supertest. Tests cover:
Run tests with:
npm test