Skip to main content

Crate rapina

Crate rapina 

Source
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_id for debugging
  • Validation - Built-in request validation using the validator crate
  • 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 bodies
  • Path - Extract path parameters
  • Query - Parse query string parameters
  • Form - Parse URL-encoded form data
  • Headers - Access request headers
  • Cookie - Extract and deserialize cookies
  • State - Access application state
  • Context - Access request context with trace_id
  • Validated - Validate extracted data

§Middleware

Built-in middleware for common use cases:

§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 http;
pub use hyper;
pub use rust_decimal;
pub use schemars;
pub use uuid;

Modules§

app
The main application builder for Rapina.
auth
Authentication system for Rapina applications.
cache
Response caching layer with pluggable backends.
config
Type-safe configuration loading from environment variables
context
discovery
Route auto-discovery via inventory.
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
Application state for dependency injection into handlers.
test
Test utilities for Rapina framework
testing
Testing utilities for Rapina applications.

Macros§

schema
Define database entities with Prisma-like syntax.

Attribute Macros§

delete
Registers a DELETE route handler.
get
Registers a GET route handler.
post
Registers a POST route handler.
public
Marks a route as public (no authentication required).
put
Registers a PUT route handler.
relay
Registers a channel handler for the relay system.

Derive Macros§

Config
Derive macro for type-safe configuration