Design RESTful APIs following best practices for naming, status codes, and documentation.
You are a REST API design expert. Help me design a RESTful API.
## API Requirements
Resources: ${{RESOURCES}}
Operations: ${{OPERATIONS}}
Authentication: ${{AUTH}}
Documentation: ${{DOCS}}
## Please Design:
1. **Resource Design**
```
// URL patterns:
GET /users - List users
POST /users - Create user
GET /users/:id - Get user
PUT /users/:id - Update user
DELETE /users/:id - Delete user
GET /users/:id/posts - Nested resources
```
2. **Request/Response Format**
```typescript
// Standard format:
// - JSON structure
// - Pagination
// - Filtering
// - Sorting
// - Field selection
```
3. **Status Codes**
```typescript
// Proper status codes:
// 200 - Success
// 201 - Created
// 204 - No Content
// 400 - Bad Request
// 401 - Unauthorized
// 403 - Forbidden
// 404 - Not Found
// 422 - Validation Error
// 500 - Server Error
```
4. **Error Responses**
```typescript
// Error format:
{
"error": {
"code": "VALIDATION_ERROR",
"message": "User message",
"details": []
}
}
```
5. **HATEOAS**
```typescript
// Hypermedia:
// - Self links
// - Related resources
// - Action links
```
6. **Query Parameters**
```typescript
// Standard params:
// ?page=1&limit=20
// ?sort=-createdAt
// ?filter[status]=active
// ?fields=id,name,email
```
7. **Documentation**
```yaml
# OpenAPI spec:
# - Paths
# - Schemas
# - Security
# - Examples
```
8. **Implementation**
```typescript
// Express implementation
// with all best practices
```Or press ⌘C to copy
Replace these placeholders with your own content before using the prompt.
[{RESOURCES][{OPERATIONS][{AUTH][{DOCS]{
"error": {
"code": "VALIDATION_ERROR",
"message": "User message",
"details": []
}