AFast
AFast is a high-performance asynchronous Rust backend framework designed to simplify building networked applications. It supports multiple protocols via feature flags and provides automatic code generation for clients (TypeScript and JavaScript), API documentation, and field validation.
Instructions
Supported Protocol Features
You can enable the following features in your Cargo.toml:
http- enable HTTP support/- Document path (feature flagdoc)/api- HTTP API endpoints/code/{service}/{lang}- Client code (feature flagjs|ts...)/doc- Service list (feature flagdoc)/doc/{service}- Handler defintions and documentation (feature flagdoc)
ws- enable WebSocket support/ws- WebSocket endpoint
tcp- enable TCP supportdoc- enable API documentation generationjs- enable JavaScript client generation (auto enabledcode)ts- enable TypeScript client generation (auto enabledcode)code- enable code generation
Note on TCP usage:
If the tcp feature is enabled, the AFast::serve method takes two arguments:
- The TCP address to listen on (
"127.0.0.1:8080"). - The HTTP/WS address (
"127.0.0.1:8081") for web clients and generated JS/TS clients.
This allows you to run TCP and HTTP/WS servers simultaneously in the same application.
Key Features
handlerMacro: Declare HTTP endpoints with minimal boilerplate- Automatic TypeScript/JavaScript client generation
- Namespace support for organized API structure (
ns("api.v1.user")) - Descriptive API documentation generation (
desc("Get user info"))
- Automatic field validation with custom rules
- Async handler functions with state management
- Flexible multi-protocol support: HTTP, WS, TCP
Handler Macro Overview
The #[handler] attribute macro transforms async functions into full-featured API endpoints:
async
Macro Parameters:
desc("description")- API description for documentationns("api.v1.user")- Namespace for nested JS client generation
Generated Output:
- Type-safe HTTP endpoints
- Nested JavaScript client structure
- TypeScript type definitions
- OpenAPI documentation
Upcoming Features / Development Plan
- Nested structure validation for complex types
- Enable or disable js / ts / document by feature flags
- Add command for generating client code
- Generate client code for additional languages: Java, Kotlin, C#, Rust, etc.
- Improved code generation templates for easier integration
- Enhanced error handling and validation reporting
Example
use ;
async
async
async
async