API Overview
The Swit framework provides a rich set of APIs for building microservice applications. This documentation provides a complete reference for the framework's core APIs.
Core APIs
Server API
The Server API is the heart of the framework, providing service lifecycle management, configuration, and dependency injection capabilities.
BusinessServerCore
- Main server interfaceServerConfig
- Server configurationBusinessServiceRegistrar
- Service registration interface
Transport API
The Transport API manages HTTP and gRPC communication.
TransportCoordinator
- Transport coordinatorNetworkTransport
- Network transport interfaceMultiTransportRegistry
- Multi-transport registry
Middleware API
The Middleware API provides extension points for request processing.
Middleware
- Middleware interfaceAuthMiddleware
- Authentication middlewareLoggingMiddleware
- Logging middleware
Service APIs
Swit Serve API
Complete REST API for user management service.
Swit Auth API
Authentication and authorization service API.
API Conventions
Request Format
All API requests should use JSON format:
{
"field1": "value1",
"field2": "value2"
}
Response Format
Standard response format:
{
"code": 0,
"message": "success",
"data": {}
}
Error Handling
Error response format:
{
"code": 400,
"message": "Invalid request",
"error": {
"field": "username",
"reason": "required"
}
}
Versioning
APIs use URL path versioning:
/api/v1/
- Version 1/api/v2/
- Version 2 (future)
Authentication
Most APIs require authentication. The following authentication methods are supported:
- Bearer Token:
Authorization: Bearer <token>
- API Key:
X-API-Key: <key>
Rate Limiting
API requests are protected by rate limiting:
- Default limit: 100 requests per minute
- Authenticated users: 1000 requests per minute