Authentication Examples
User Login
POST /api/auth/login
Request
{
"email": "user@example.com",
"password": "securepassword"
}
Response
{
"success": true,
"user": {
"id": "123",
"email": "user@example.com",
"name": "John Doe"
},
"session": "session_token_here"
}
User Management Examples
Get Users List
GET /api/users
Headers
Authorization: Bearer your_token
Content-Type: application/json
Response
{
"success": true,
"users": [
{
"id": "123",
"email": "user@example.com",
"name": "John Doe",
"role": "admin"
}
]
}
Dashboard Examples
Get Dashboard Statistics
GET /api/dashboard/stats
Headers
Authorization: Bearer your_token
Content-Type: application/json
Response
{
"success": true,
"stats": {
"totalUsers": 150,
"activeConnections": 45,
"totalRelayServers": 12,
"uptime": "99.9%"
}
}
Error Handling Examples
Authentication Error
401 Unauthorized
{
"success": false,
"error": "Authentication required",
"code": "AUTH_REQUIRED"
}
Validation Error
400 Bad Request
{
"success": false,
"error": "Invalid email format",
"code": "VALIDATION_ERROR",
"details": {
"field": "email",
"message": "Must be a valid email address"
}
}
Best Practices
Security
- Always use HTTPS for API calls
- Store tokens securely and never expose them
- Implement proper error handling
- Use rate limiting to avoid API abuse
Performance
- Cache responses when appropriate
- Use pagination for large datasets
- Implement retry logic for failed requests
- Monitor API usage and performance