API Reference Overview
The Ever Works provides a comprehensive REST API built with Next.js API routes. This section documents all available endpoints, authentication methods, and usage examples.
Base URL
Development: http://localhost:3000/api
Production: https://yourdomain.com/api
Authentication
The API supports multiple authentication methods:
1. Session-based Authentication
Used for web application requests:
// Automatic for browser requests with valid session
fetch('/api/items', {
credentials: 'include'
})
2. API Key Authentication
For server-to-server requests:
fetch('/api/items', {
headers: {
'Authorization': 'Bearer your-api-key'
}
})
3. JWT Token Authentication
For mobile or SPA applications:
fetch('/api/items', {
headers: {
'Authorization': 'Bearer your-jwt-token'
}
})
Response Format
All API responses follow a consistent format:
Success Response
{
"success": true,
"data": {
// Response data
},
"meta": {
"timestamp": "2024-01-15T10:30:00Z",
"version": "1.0.0"
}
}
Error Response
{
"success": false,
"error": {
"code": "VALIDATION_ERROR",
"message": "Invalid input data",
"details": {
"field": "email",
"issue": "Invalid email format"
}
},
"meta": {
"timestamp": "2024-01-15T10:30:00Z",
"version": "1.0.0"
}
}
Paginated Response
{
"success": true,
"data": [
// Array of items
],
"pagination": {
"page": 1,
"limit": 20,
"total": 150,
"totalPages": 8,
"hasNext": true,
"hasPrev": false
},
"meta": {
"timestamp": "2024-01-15T10:30:00Z",
"version": "1.0.0"
}
}
HTTP Status Codes
| Code | Description |
|---|---|
| 200 | OK - Request successful |
| 201 | Created - Resource created successfully |
| 400 | Bad Request - Invalid request data |
| 401 | Unauthorized - Authentication required |
| 403 | Forbidden - Insufficient permissions |
| 404 | Not Found - Resource not found |
| 409 | Conflict - Resource already exists |
| 422 | Unprocessable Entity - Validation error |
| 429 | Too Many Requests - Rate limit exceeded |
| 500 | Internal Server Error - Server error |
Rate Limiting
API endpoints are rate-limited to prevent abuse:
| Endpoint Type | Limit | Window |
|---|---|---|
| Public endpoints | 100 requests | 15 minutes |
| Authenticated endpoints | 1000 requests | 15 minutes |
| Admin endpoints | 5000 requests | 15 minutes |
| Webhook endpoints | 10000 requests | 15 minutes |
Rate limit headers are included in responses:
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 95
X-RateLimit-Reset: 1642234567
API Endpoints Overview
Public Endpoints
Items
GET /api/items- List items with filteringGET /api/items/[id]- Get item detailsGET /api/items/[slug]- Get item by slug
Categories
GET /api/categories- List all categoriesGET /api/categories/[slug]- Get category details
Tags
GET /api/tags- List all tagsGET /api/tags/[slug]- Get tag details
Search
GET /api/search- Search items, categories, and tags
Authentication Endpoints
Auth
POST /api/auth/signin- Sign in userPOST /api/auth/signout- Sign out userGET /api/auth/session- Get current sessionPOST /api/auth/signup- Register new user
User Management
GET /api/user/profile- Get user profilePUT /api/user/profile- Update user profilePOST /api/user/change-password- Change password
Protected Endpoints
Favorites
GET /api/favorites- Get user favoritesPOST /api/favorites- Add item to favoritesDELETE /api/favorites/[slug]- Remove from favorites
Submissions
POST /api/submit- Submit new itemGET /api/submissions- Get user submissionsPUT /api/submissions/[id]- Update submission
Admin Endpoints
Admin Items
GET /api/admin/items- List all items (admin view)POST /api/admin/items- Create new itemPUT /api/admin/items/[id]- Update itemDELETE /api/admin/items/[id]- Delete itemPOST /api/admin/items/[id]/approve- Approve itemPOST /api/admin/items/[id]/reject- Reject item