API Design Principles
RESTful API design patterns and conventions used throughout the platform
Our API follows REST principles and industry best practices for consistency and ease of use.
Base URL
All API requests should be made to:
https://api.example.com/v1HTTP Methods
We use standard HTTP methods:
| Method | Usage |
|---|---|
| GET | Retrieve resources |
| POST | Create new resources |
| PUT | Update entire resource |
| PATCH | Partially update resource |
| DELETE | Remove resource |
Request Format
Headers
Content-Type: application/json
Authorization: Bearer {access_token}
X-Request-ID: {unique-request-id}Request Body
{
"name": "Example Resource",
"description": "This is an example",
"metadata": {
"key": "value"
}
}Response Format
Success Response (200 OK)
{
"data": {
"id": "123",
"name": "Example Resource",
"created_at": "2025-01-15T10:30:00Z"
},
"meta": {
"request_id": "req_abc123"
}
}Error Response (400 Bad Request)
{
"error": {
"code": "validation_error",
"message": "Invalid input provided",
"details": [
{
"field": "email",
"message": "Email format is invalid"
}
]
},
"meta": {
"request_id": "req_abc123"
}
}Status Codes
Common status codes you’ll encounter:
200 OK- Successful request201 Created- Resource created successfully204 No Content- Successful deletion400 Bad Request- Invalid request parameters401 Unauthorized- Authentication required403 Forbidden- Insufficient permissions404 Not Found- Resource doesn’t exist429 Too Many Requests- Rate limit exceeded500 Internal Server Error- Server error
Pagination
List endpoints support pagination:
GET /api/v1/resources?page=2&per_page=50Response includes pagination metadata:
{
"data": [...],
"meta": {
"page": 2,
"per_page": 50,
"total": 250,
"total_pages": 5
}
}Filtering and Sorting
Filtering
GET /api/v1/resources?filter[status]=active&filter[type]=premiumSorting
GET /api/v1/resources?sort=-created_at,name- Prefix with
-for descending order - Multiple sort fields separated by commas
Versioning
API versioning is done via URL path:
/v1/- Current stable version/v2/- Next major version (when available)
Rate Limiting
Rate limit information is included in response headers:
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 85
X-RateLimit-Reset: 1609459200Best Practices
- Always include proper error handling
- Use request IDs for debugging
- Implement exponential backoff for retries
- Cache responses when appropriate
- Use compression for large payloads
- Monitor rate limits proactively