v2/examples/05-swarm-apps/rest-api/API.md
http://localhost:3000/api/v1
Currently, this API does not require authentication. In production, you should implement proper authentication.
Content-Type: application/json
Accept: application/json
GET /api/v1/users
Query Parameters:
page (integer): Page number (default: 1)limit (integer): Items per page (default: 10)sort (string): Sort field (id, name, email, age)Response:
{
"success": true,
"data": [
{
"id": 1,
"name": "John Doe",
"email": "[email protected]",
"age": 30,
"createdAt": "2024-01-13T12:00:00.000Z"
}
],
"pagination": {
"page": 1,
"limit": 10,
"total": 3
}
}
GET /api/v1/users/:id
Response:
{
"success": true,
"data": {
"id": 1,
"name": "John Doe",
"email": "[email protected]",
"age": 30,
"createdAt": "2024-01-13T12:00:00.000Z"
}
}
POST /api/v1/users
Request Body:
{
"name": "Jane Smith",
"email": "[email protected]",
"age": 25
}
Response (201 Created):
{
"success": true,
"message": "User created successfully",
"data": {
"id": 4,
"name": "Jane Smith",
"email": "[email protected]",
"age": 25,
"createdAt": "2024-01-13T12:00:00.000Z"
}
}
PUT /api/v1/users/:id
Request Body:
{
"name": "Jane Doe",
"email": "[email protected]",
"age": 26
}
Response:
{
"success": true,
"message": "User updated successfully",
"data": {
"id": 4,
"name": "Jane Doe",
"email": "[email protected]",
"age": 26,
"updatedAt": "2024-01-13T12:30:00.000Z"
}
}
DELETE /api/v1/users/:id
Response:
{
"success": true,
"message": "User deleted successfully"
}
GET /api/v1/products
Query Parameters:
page (integer): Page number (default: 1)limit (integer): Items per page (default: 10)category (string): Filter by categoryminPrice (number): Minimum price filtermaxPrice (number): Maximum price filterResponse:
{
"success": true,
"data": [
{
"id": 1,
"name": "Laptop",
"price": 999.99,
"category": "Electronics",
"stock": 50,
"description": "High-performance laptop",
"createdAt": "2024-01-13T12:00:00.000Z"
}
],
"pagination": {
"page": 1,
"limit": 10,
"total": 4
}
}
GET /api/v1/products/:id
Response:
{
"success": true,
"data": {
"id": 1,
"name": "Laptop",
"price": 999.99,
"category": "Electronics",
"stock": 50,
"description": "High-performance laptop",
"createdAt": "2024-01-13T12:00:00.000Z"
}
}
POST /api/v1/products
Request Body:
{
"name": "Wireless Mouse",
"price": 29.99,
"category": "Accessories",
"stock": 100,
"description": "Ergonomic wireless mouse"
}
Response (201 Created):
{
"success": true,
"message": "Product created successfully",
"data": {
"id": 5,
"name": "Wireless Mouse",
"price": 29.99,
"category": "Accessories",
"stock": 100,
"description": "Ergonomic wireless mouse",
"createdAt": "2024-01-13T12:00:00.000Z"
}
}
PUT /api/v1/products/:id
Request Body:
{
"name": "Gaming Mouse",
"price": 49.99,
"category": "Gaming",
"stock": 75,
"description": "RGB gaming mouse with programmable buttons"
}
Response:
{
"success": true,
"message": "Product updated successfully",
"data": {
"id": 5,
"name": "Gaming Mouse",
"price": 49.99,
"category": "Gaming",
"stock": 75,
"description": "RGB gaming mouse with programmable buttons",
"updatedAt": "2024-01-13T12:30:00.000Z"
}
}
DELETE /api/v1/products/:id
Response:
{
"success": true,
"message": "Product deleted successfully"
}
{
"errors": [
{
"type": "field",
"value": "invalid-email",
"msg": "Valid email is required",
"path": "email",
"location": "body"
}
]
}
{
"success": false,
"message": "User not found"
}
{
"success": false,
"error": {
"message": "Internal Server Error",
"status": 500,
"timestamp": "2024-01-13T12:00:00.000Z"
}
}
The API implements rate limiting (default: 100 requests per hour per IP). When exceeded:
{
"success": false,
"error": {
"message": "Too many requests",
"status": 429,
"timestamp": "2024-01-13T12:00:00.000Z"
}
}
The API supports CORS for all origins in development. Configure appropriate origins for production.
The API uses URL versioning (currently v1). Future versions will be available at /api/v2, etc.