serverust Framework
Framework Rust opinativo para APIs HTTP e AWS Lambda, inspirado em Axum + FastAPI + NestJS.
🦀 Comece aqui:
- Getting Started — em 5 minutos, hello-world local com Swagger UI.
- Tutorial Lambda — passo-a-passo do zero ao deploy em AWS Lambda.
Documentação completa: docs/INDEX.md.
Por que serverust?
O único framework Rust que cobre todo o ciclo — do serverust new ao serverust deploy — com suporte nativo a AWS Lambda, OpenAPI automático e DI em um único binário leve.
| serverust | Rocket | Loco.rs | Axum (raw) | |
|---|---|---|---|---|
| AWS Lambda nativo | ✅ | ❌ | ❌ | ❌ |
| Runtime dual HTTP ↔ Lambda | ✅ | ❌ | ❌ | ❌ |
| OpenAPI 3.1 automático | ✅ | via plugin | via plugin | ❌ |
| Scalar / Swagger UI embutido | ✅ | ❌ | ❌ | ❌ |
| Validação → HTTP 422 | ✅ | via plugin | ✅ | ❌ |
| Dependency Injection nativo | ✅ | ❌ | ❌ | ❌ |
CLI scaffolding (new, generate) |
✅ | ❌ | ✅ | ❌ |
| Cold start < 50 ms (ARM64 128 MB) | ✅ | ✗ | ✗ | ✅ |
| Binário stripped < 10 MB | ✅ | ✗ | ✗ | ✅ |
Features
- Roteamento declarativo via macros (
#[get],#[post],#[put],#[patch],#[delete]) - Validação automática de payloads com
#[derive(Validate)]→ HTTP 422 padronizado - OpenAPI 3.1 + Scalar API Reference automáticos via utoipa
- Dependency Injection híbrido (
Arc<dyn Trait>+ builder) - Guards, Pipes e Interceptors para cross-cutting concerns
- Runtime dual: detecta automaticamente HTTP local vs AWS Lambda
- Telemetria nativa: logs JSON, tracing X-Ray, métricas EMF
- CLI:
serverust new/generate/dev/build/deploy/info/openapi - Configuração via
serverust.toml+ env vars (figment)
Requisitos
- Rust 1.85+ (Edition 2024)
- Para deploy Lambda:
cargo-lambda
Estrutura do Workspace
serverust-core/ # App builder, Route, validação, DI, pipeline
serverust-macros/ # Proc-macros: #[get], #[post], #[injectable], etc.
serverust-cli/ # CLI serverust com clap
serverust-lambda/ # Runtime dual Lambda + HTTP via AppRuntime trait
serverust-telemetry/ # Logger JSON, tracing, métricas EMF
examples/
hello-world/ # Mínimo para benchmark de cold start
funds-api/ # CRUD completo: validação, OpenAPI, DI
scripts/
bench.sh # Benchmark de tamanho e cold start
Início Rápido
Criar um novo projeto
Exemplo mínimo
use App;
use AppRuntime;
use get;
async
async
CRUD com validação e DI
use Arc;
use ;
use AppRuntime;
use ;
use ;
use ToSchema;
use Validate;
;
async
async
async
Configuração (serverust.toml)
Usa figment com suporte a profiles e override por env vars:
[]
= "127.0.0.1"
= 3000
[]
= 128
= 30
[]
= "info"
= "json"
[]
= "My API"
= "0.1.0"
= "/docs"
= "/redoc"
# Overrides por perfil:
[]
= 3001
[]
= "0.0.0.0"
= 8080
Seleção de perfil: SERVERUST_PROFILE=prod ou ServerustConfig::load_for_profile("prod").
Override por env: SERVERUST_SERVER__PORT=8080, SERVERUST_TELEMETRY__LOG_LEVEL=debug.
Carregar no handler:
use ServerustConfig;
let cfg = load.unwrap_or_default;
new.config.route
// handler: State<Arc<ServerustConfig>>
Exemplos
Rodar funds-api localmente
# Acesse: http://localhost:3000/docs (Swagger UI)
# Acesse: http://localhost:3000/openapi.json
Rodar hello-world localmente
# GET http://localhost:3000/
Deploy em Lambda
# Instalar cargo-lambda
# Deploy do funds-api (ARM64)
# Ou manualmente:
Benchmark
# Tamanho do binário stripped e startup local:
# Incluir benchmark de cold start em Lambda (requer AWS CLI):
LAMBDA_FUNCTION_NAME=serverust-hello-world-bench
Alvos de performance:
- Cold start Lambda ARM64 128MB: < 50ms
- Binário stripped: < 10 MB
Rodar Testes
CLI
||||||