- Create comprehensive documentation system integrated with Hono app - Add beautiful glass morphism design with gradient backgrounds - Implement dramatically larger heading hierarchy (H1: 72px, H2: 48px, H3: 30px) - Add interactive elements: hover effects, animations, numbered sections - Include syntax highlighting for code blocks with dark theme - Create responsive design with custom scrollbars and mobile optimization - Add breadcrumb navigation and enhanced footer - Implement high-specificity CSS to override Tailwind prose defaults - Add cache-busting headers for immediate style updates - Include auto-numbered section badges and decorative elements - Support for Workers-compatible markdown rendering without fs dependencies
4.5 KiB
4.5 KiB
API Reference
SonicJS AI provides a comprehensive REST API for managing content, media, and other resources programmatically.
Base URL
https://your-domain.com/api
For local development:
http://localhost:8787/api
Authentication
Most API endpoints require authentication. SonicJS AI uses JWT (JSON Web Tokens) for authentication.
Getting an Access Token
POST /api/auth/login
Content-Type: application/json
{
"email": "user@example.com",
"password": "your-password"
}
Response:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"user": {
"id": "1",
"name": "John Doe",
"email": "user@example.com"
}
}
Using the Token
Include the token in the Authorization header:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Content Management
List Content Items
GET /api/content
Query Parameters:
page(optional): Page number (default: 1)limit(optional): Items per page (default: 10)type(optional): Filter by content type
Response:
{
"data": [
{
"id": "1",
"title": "My First Post",
"slug": "my-first-post",
"type": "post",
"status": "published",
"content": "Lorem ipsum dolor sit amet...",
"createdAt": "2024-01-15T10:30:00Z",
"updatedAt": "2024-01-15T10:30:00Z"
}
],
"pagination": {
"page": 1,
"limit": 10,
"total": 1,
"pages": 1
}
}
Get Content Item by ID
GET /api/content/{id}
Create Content Item
POST /api/content
Content-Type: application/json
Authorization: Bearer {token}
{
"title": "New Blog Post",
"slug": "new-blog-post",
"type": "post",
"content": "This is the content of my new blog post...",
"status": "draft"
}
Update Content Item
PUT /api/content/{id}
Content-Type: application/json
Authorization: Bearer {token}
{
"title": "Updated Title",
"content": "Updated content..."
}
Delete Content Item
DELETE /api/content/{id}
Authorization: Bearer {token}
Media Management
Upload File
POST /api/media/upload
Content-Type: multipart/form-data
Authorization: Bearer {token}
file: [binary data]
Response:
{
"id": "abc123",
"filename": "image.jpg",
"originalName": "my-image.jpg",
"mimeType": "image/jpeg",
"size": 102400,
"url": "https://your-domain.com/media/abc123/image.jpg",
"uploadedAt": "2024-01-15T10:30:00Z"
}
List Media Files
GET /api/media
Query Parameters:
page(optional): Page numberlimit(optional): Items per pagetype(optional): Filter by MIME type (image, video, document)
Get Media File Details
GET /api/media/{id}
Delete Media File
DELETE /api/media/{id}
Authorization: Bearer {token}
Error Handling
The API uses standard HTTP status codes to indicate success or failure:
200- Success201- Created400- Bad Request401- Unauthorized403- Forbidden404- Not Found500- Internal Server Error
Error Response Format:
{
"error": {
"code": "VALIDATION_ERROR",
"message": "Title is required",
"details": {
"field": "title",
"value": null
}
}
}
Rate Limiting
The API implements rate limiting to ensure fair usage:
- Authenticated requests: 1000 requests per hour
- Unauthenticated requests: 100 requests per hour
Rate limit headers are included in responses:
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 999
X-RateLimit-Reset: 1640995200
OpenAPI Specification
For a complete, interactive API reference, visit:
- Scalar UI - Modern API documentation
- Swagger UI - Traditional Swagger interface
- OpenAPI JSON - Raw OpenAPI specification
SDKs and Libraries
Official SDKs are coming soon! In the meantime, you can use any HTTP client library:
JavaScript/TypeScript
const response = await fetch('/api/content', {
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
}
});
const data = await response.json();
cURL
curl -X GET "https://your-domain.com/api/content" \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json"