mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-23 21:59:14 +09:00
5.1 KiB
5.1 KiB
REST API Documentation
Base URL
http://localhost:3000/api/v1
Authentication
Currently, this API does not require authentication. In production, you should implement proper authentication.
Common Headers
Content-Type: application/json
Accept: application/json
Endpoints
Users Resource
List Users
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": "john@example.com",
"age": 30,
"createdAt": "2024-01-13T12:00:00.000Z"
}
],
"pagination": {
"page": 1,
"limit": 10,
"total": 3
}
}
Get User
GET /api/v1/users/:id
Response:
{
"success": true,
"data": {
"id": 1,
"name": "John Doe",
"email": "john@example.com",
"age": 30,
"createdAt": "2024-01-13T12:00:00.000Z"
}
}
Create User
POST /api/v1/users
Request Body:
{
"name": "Jane Smith",
"email": "jane@example.com",
"age": 25
}
Response (201 Created):
{
"success": true,
"message": "User created successfully",
"data": {
"id": 4,
"name": "Jane Smith",
"email": "jane@example.com",
"age": 25,
"createdAt": "2024-01-13T12:00:00.000Z"
}
}
Update User
PUT /api/v1/users/:id
Request Body:
{
"name": "Jane Doe",
"email": "jane.doe@example.com",
"age": 26
}
Response:
{
"success": true,
"message": "User updated successfully",
"data": {
"id": 4,
"name": "Jane Doe",
"email": "jane.doe@example.com",
"age": 26,
"updatedAt": "2024-01-13T12:30:00.000Z"
}
}
Delete User
DELETE /api/v1/users/:id
Response:
{
"success": true,
"message": "User deleted successfully"
}
Products Resource
List Products
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 filter
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"
}
],
"pagination": {
"page": 1,
"limit": 10,
"total": 4
}
}
Get Product
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"
}
}
Create Product
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"
}
}
Update Product
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 Product
DELETE /api/v1/products/:id
Response:
{
"success": true,
"message": "Product deleted successfully"
}
Error Responses
Validation Error (400)
{
"errors": [
{
"type": "field",
"value": "invalid-email",
"msg": "Valid email is required",
"path": "email",
"location": "body"
}
]
}
Not Found (404)
{
"success": false,
"message": "User not found"
}
Server Error (500)
{
"success": false,
"error": {
"message": "Internal Server Error",
"status": 500,
"timestamp": "2024-01-13T12:00:00.000Z"
}
}
Rate Limiting
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"
}
}
CORS
The API supports CORS for all origins in development. Configure appropriate origins for production.
Versioning
The API uses URL versioning (currently v1). Future versions will be available at /api/v2, etc.