Expand description
§Rapina
A fast, type-safe web framework for Rust inspired by FastAPI.
Rapina focuses on productivity, type safety, and clear conventions, making it easy to build production-ready APIs.
§Features
- Type-safe extractors - Parse request data with compile-time guarantees
- Declarative routing - Use proc macros like
#[get],#[post]for clean route definitions - Middleware system - Composable middleware with async support
- Structured errors - Standardized error responses with
trace_idfor debugging - Validation - Built-in request validation using the
validatorcrate - Observability - Integrated tracing for structured logging
§Quick Start
ⓘ
use rapina::prelude::*;
#[get("/")]
async fn hello() -> &'static str {
"Hello, Rapina!"
}
#[get("/users/:id")]
async fn get_user(id: Path<u64>) -> Result<Json<serde_json::Value>> {
let id = id.into_inner();
Ok(Json(serde_json::json!({ "id": id })))
}
#[tokio::main]
async fn main() -> std::io::Result<()> {
let router = Router::new()
.get("/", hello)
.get("/users/:id", get_user);
Rapina::new()
.router(router)
.listen("127.0.0.1:3000")
.await
}§Extractors
Rapina provides several extractors for parsing request data:
Json- Parse JSON request bodiesPath- Extract path parametersQuery- Parse query string parametersForm- Parse URL-encoded form dataHeaders- Access request headersState- Access application stateContext- Access request context with trace_idValidated- Validate extracted data
§Middleware
Built-in middleware for common use cases:
TimeoutMiddleware- Request timeout handlingBodyLimitMiddleware- Limit request body sizeTraceIdMiddleware- Add trace IDs to requestsRequestLogMiddleware- Structured request logging
§Introspection
Access route metadata for documentation and tooling:
RouteInfo- Metadata about registered routes
§Testing
Integration testing utilities:
TestClient- Test client for integration testing
Re-exports§
pub use schemars;
Modules§
- app
- The main application builder for Rapina.
- auth
- Authentication system for Rapina applications.
- config
- Type-safe configuration loading from environment variables
- context
- error
- Standardized error handling for Rapina applications.
- extract
- Request extractors for parsing incoming HTTP requests.
- handler
- Handler trait for named route handlers.
- introspection
- Introspection utilities for Rapina applications.
- middleware
- Middleware system for Rapina applications.
- observability
- Observability utilities for Rapina applications.
- openapi
- prelude
- Convenient re-exports for common Rapina types.
- response
- Response types and conversion traits.
- router
- HTTP routing for Rapina applications.
- server
- state
- test
- Test utilities for Rapina framework
- testing
- Testing utilities for Rapina applications.