็ฎไฝไธญๆ | English | ๐ Documentation
A high-performance Rust web framework. Annotate functions with #[handler] โ the framework auto-registers routes, dispatches requests via a compact binary protocol, and generates TypeScript / JavaScript / Kotlin / Rust / C# client code with one click.
- Zero Route Definitions โ
#[handler]annotation, no manual routing table - Compact Binary Protocol โ smaller and faster than JSON
- Auto Code Generation โ TypeScript / JavaScript / Kotlin / Rust / C# clients
- Interactive API Docs โ built-in Web docs with online testing
- Multiple Transports โ WebSocket, HTTP/1.1, HTTP/2, TCP
- TLS / HTTPS โ rustls with ALPN for HTTP/2, hot-reload via channel
- File Upload โ
Multipart(raw) andMultipartForm<T>(typed) extractors with#[derive(FromFormData)] - RESTful Endpoints โ
#[get]/#[post]/#[put]/#[delete]with JSON - WebSocket & SSE โ
#[ws]and#[sse]route macros - Long Connections โ bidirectional streaming via
Receiver/Sender - Zero-Copy State โ
State<T>holds&'static T, no per-request clone - Lifecycle Hooks โ
before_request/on_response/on_error/on_connect/on_disconnect - Request Context โ
Ctx<T>per-request context, hooks write, handlers read - Rate Limiting โ named policies with pluggable storage backend
- Client-Side Caching โ
cache(seconds)attribute
[dependencies]
afast = { version = "0.1.25", features = ["http", "ordinary-http"] }
tokio = { version = "1", features = ["full"] }use afast::{AFast, Ctx, handler, service, State, Data, Result};
use afast::{AFastDeserialize, AFastSerialize, Tag};
struct AppState { greeting: String }
#[derive(Clone)]
struct RequestId(pub String);
#[derive(AFastDeserialize, Tag)]
#[tag("Hello request")]
struct HelloReq { name: String }
#[derive(AFastSerialize, Tag)]
#[tag("Hello response")]
struct HelloResp { message: String }
#[handler(desc("Say hello"))]
async fn hello(
ctx: Ctx<RequestId>,
state: State<AppState>,
req: Data<HelloReq>,
) -> Result<HelloResp> {
println!("request_id={}", ctx.0 .0);
Ok(HelloResp { message: format!("{}, {}!", state.greeting, req.name) })
}
#[tokio::main]
async fn main() {
let svc = service!("api" => { h(hello) });
AFast::new()
.state(AppState { greeting: "Hello".into() })
.service(svc)
.http("0.0.0.0:5000")
.run().await.unwrap();
}๐ afast.ahriknow.help โ Quick Start, Core Concepts, Features, Hooks, Rate Limiting, Code Generation, Binary Protocol, and more.
afast/ โ Main framework crate
afast-macros/ โ Proc macros (#[handler], service!, #[derive(Tag)])
example/ โ Example project with full usage
docs/ โ Documentation source (mdbook)
MIT