API Overview
REST API with JSON responses
API Overview
Our REST API provides programmatic access to the platform. The API includes both public demo endpoints and protected endpoints that require API key authentication.
Base URL
http://localhost:8000/api/v1
Try it Now!
Test our API with this simple demo endpoint that returns the current year:
bash
# No authentication required - try it now!
curl http://localhost:8000/api/v1/demo/year
# Response:
{
"year": 2025,
"message": "The current year is 2025",
"timestamp": "2025-01-18T12:00:00.000Z"
}
Check the API status endpoint:
bash
# Without authentication
curl http://localhost:8000/api/v1/status
# Response:
{
"status": "operational",
"version": "1.0.0",
"authenticated": false
}
WebSocket Demo
Test real-time communication with our WebSocket endpoints:
javascript
// 1. Public WebSocket echo server - no authentication required
const ws = new WebSocket('ws://localhost:8000/api/v1/ws/echo');
ws.onopen = () => {
console.log('Connected to WebSocket');
ws.send('Hello, WebSocket!');
};
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log('Received:', data);
// Output: { type: "echo", message: "Hello, WebSocket!", timestamp: "...", server_time: "..." }
};
// 2. Protected time broadcast endpoint - requires API key
const apiKey = 'sk_live_your_api_key_here';
const timews = new WebSocket(`ws://localhost:8000/api/v1/ws/time?api_key=${apiKey}`);
timews.onmessage = (event) => {
const data = JSON.parse(event.data);
if (data.type === 'auth_success') {
console.log('Authenticated:', data.api_key_name);
} else if (data.type === 'time_update') {
console.log('Server time:', data.formatted);
}
};
timews.onerror = (error) => {
console.error('WebSocket error - check your API key');
};