rapid-rs 0.3.2

Zero-config, batteries-included web framework for Rust - FastAPI meets Spring Boot
Documentation

๐Ÿš€ rapid-rs

Zero-config, batteries-included web framework for Rust
FastAPI meets Spring Boot, powered by Axum

Crates.io Documentation License

๐Ÿ†• What's New in v0.3.0

Phase 2 Complete! ๐ŸŽ‰

  • ๐Ÿ—„๏ธ Database Migrations - Automatic migration management with sqlx
  • ๐Ÿงช Testing Utilities - Comprehensive testing framework for APIs
  • ๐Ÿ“š GraphQL & gRPC Templates - Ready-to-use project scaffolding
// Database with auto-migrations
use rapid_rs::database::{connect_and_migrate, MigrationConfig};

let pool = connect_and_migrate(
    "postgres://localhost/myapp",
    MigrationConfig::default()
).await?;
// Easy API testing
use rapid_rs::testing::TestClient;

let client = TestClient::new(app);
let response = client.get("/users").await;
response.assert_status(StatusCode::OK);

See full changelog โ†’


Why rapid-rs?

Building web APIs in Rust shouldn't require wiring together 10+ crates and writing hundreds of lines of boilerplate. rapid-rs gives you the productivity of FastAPI and Spring Boot, with Rust's performance and type safety.

โšก Features

  • ๐ŸŽฏ Zero Config - Database, migrations, CORS, logging work out of the box
  • ๐Ÿ—„๏ธ Auto Migrations - Database migrations run automatically on startup (NEW!)
  • ๐Ÿ” Built-in Auth - JWT authentication, password hashing, RBAC
  • ๐Ÿงช Testing Suite - Comprehensive testing utilities included (NEW!)
  • ๐Ÿ”’ Type-Safe - Compile-time guarantees for routes, validation, serialization
  • ๐Ÿ“š Auto Docs - Swagger UI and OpenAPI specs from your code
  • โœ… Validation - Request validation with helpful error messages
  • ๐Ÿ”ฅ Hot Reload - Fast development with rapid dev
  • ๐ŸŽจ Opinionated - Convention over configuration
  • ๐Ÿš€ Production Ready - Structured logging, error handling, health checks

Quick Start

Installation

cargo install rapid-rs-cli

Create Your First API

# REST API (default)

rapid new myapi


# GraphQL API (NEW!)

rapid new mygraphql --template graphql


# gRPC service (NEW!)

rapid new mygrpc --template grpc


cd myapi

cargo run

Your API is now running at:

  • ๐ŸŒ http://localhost:8080 - API endpoints
  • ๐Ÿ“š http://localhost:8080/docs - Swagger UI
  • ๐Ÿ’š http://localhost:8080/health - Health check

Your First Endpoint with Database

use rapid_rs::prelude::*;
use rapid_rs::database::{connect_and_migrate, MigrationConfig};

#[derive(Serialize, Deserialize, Validate)]
struct CreateUser {
    #[validate(email)]
    email: String,
    #[validate(length(min = 2))]
    name: String,
}

async fn create_user(
    State(pool): State<PgPool>,
    ValidatedJson(payload): ValidatedJson<CreateUser>
) -> ApiResult<User> {
    let user = sqlx::query_as!(
        User,
        "INSERT INTO users (email, name) VALUES ($1, $2) RETURNING *",
        payload.email,
        payload.name
    )
    .fetch_one(&pool)
    .await?;
    
    Ok(Json(user))
}

#[tokio::main]
async fn main() {
    // Auto-create database and run migrations
    let pool = connect_and_migrate(
        "postgres://localhost/myapp",
        MigrationConfig::default()
    ).await.unwrap();
    
    App::new()
        .auto_configure()
        .route("/users", post(create_user))
        .with_state(pool)
        .run()
        .await
        .unwrap();
}

That's it! You get:

  • โœ… Automatic database creation
  • โœ… Automatic migration running
  • โœ… Request validation
  • โœ… Type-safe database queries
  • โœ… Structured error handling
  • โœ… OpenAPI documentation

Comparison

Feature FastAPI Spring Boot rapid-rs
Type Safety โŒ Runtime โš ๏ธ Runtime โœ… Compile-time
Auto OpenAPI โœ… โœ… โœ…
Auto Migrations โš ๏ธ Alembic โœ… โœ…
Testing Utils โš ๏ธ Partial โœ… โœ…
Hot Reload โœ… โœ… โœ…
Zero Config โœ… โœ… โœ…
Performance โš ๏ธ Good โš ๏ธ Good โœ… Blazing Fast
Memory Safety โŒ โŒ โœ… Guaranteed
Async by Default โš ๏ธ Partial โŒ โœ…
Learning Curve Easy Medium Easy

What's Included?

๐ŸŽ Out of the Box

  • Configuration - TOML files + environment variables
  • Authentication - JWT-based auth with role-based access control
  • Database - PostgreSQL with connection pooling and migrations
  • Validation - Derive-based validation with helpful errors
  • Error Handling - Centralized error handling with proper HTTP codes
  • CORS - Sensible defaults, fully configurable
  • Logging - Structured logging with request correlation
  • Health Checks - /health endpoint for orchestration
  • OpenAPI/Swagger - Auto-generated docs at /docs
  • Testing - Comprehensive testing utilities (NEW!)

๐Ÿ“ฆ CLI Tool

# Create project with template

rapid new myapi --template rest-api|graphql|grpc


# Run with hot reload

rapid dev

๐Ÿ“š Project Templates

  • REST API - Full CRUD with authentication and database
  • GraphQL API - async-graphql with subscriptions support
  • gRPC Service - tonic-based microservice template

Database Migrations

Migrations run automatically on startup:

use rapid_rs::database::{connect_and_migrate, MigrationConfig};

let config = MigrationConfig::new()
    .migrations_path("./migrations")
    .auto_migrate(true)
    .create_db_if_missing(true);

let pool = connect_and_migrate(&database_url, config).await?;

Create migrations with sqlx-cli:

cargo install sqlx-cli

sqlx migrate add create_users

Learn more about migrations โ†’

Testing Your API

Built-in testing utilities make API testing a breeze:

use rapid_rs::testing::TestClient;

#[tokio::test]
async fn test_create_user() {
    let app = setup_app();
    let client = TestClient::new(app);
    
    let response = client.post("/users", &json!({
        "email": "test@example.com",
        "name": "Test User"
    })).await;
    
    response.assert_status(StatusCode::CREATED);
    let user: User = response.json();
    assert_eq!(user.email, "test@example.com");
}

Learn more about testing โ†’

Authentication

Complete JWT authentication system included:

use rapid_rs::auth::{AuthConfig, auth_routes, AuthUser};

// Protected route
async fn protected(user: AuthUser) -> impl IntoResponse {
    format!("Hello, {}!", user.email)
}

#[tokio::main]
async fn main() {
    App::new()
        .auto_configure()
        .mount(auth_routes(AuthConfig::from_env()))
        .route("/protected", get(protected))
        .run()
        .await
        .unwrap();
}

Learn more about authentication โ†’

Configuration

Configuration loads from multiple sources:

# config/default.toml

[server]

host = "0.0.0.0"

port = 8080



[database]

url = "postgres://localhost/mydb"

Override with environment variables:

APP__SERVER__PORT=8080 cargo run

AUTH_JWT_SECRET="your-secret-key" cargo run

Examples

Check out the examples directory:

  • โœ… REST API - Full CRUD with validation and database
  • โœ… Auth API - JWT authentication with protected routes
  • โœ… GraphQL API - Complete GraphQL server (NEW!)
  • โœ… gRPC Service - Microservice with protocol buffers (NEW!)

Roadmap

Phase 1 โœ… Complete

  • Core framework with auto-configuration
  • Request validation
  • OpenAPI generation
  • CLI tool
  • Hot reload

Phase 2 โœ… Complete (v0.3.0)

  • Authentication & Authorization
  • Database migrations management
  • Testing utilities
  • GraphQL template
  • gRPC template

Phase 3 (Future)

  • Background jobs
  • WebSocket support
  • Multi-tenancy
  • Feature flags
  • Admin panel generation
  • Metrics and observability
  • Rate limiting
  • Caching layer

Contributing

Contributions welcome! This project has completed Phase 2 with lots of opportunities for Phase 3 features.

Development Setup

git clone https://github.com/ashishjsharda/rapid-rs

cd rapid-rs

cargo build

cargo test


# Run examples

cd examples/rest-api

cargo run

Contributing Guide โ†’

Philosophy

rapid-rs is built on these principles:

  1. Convention over Configuration - Sensible defaults, minimal boilerplate
  2. Type Safety First - Leverage Rust's type system
  3. Developer Experience - Make the common case easy
  4. Production Ready - Observability and best practices by default
  5. Composable - Built on Axum, use Axum patterns when needed

Why Not Just Use Axum?

Axum is fantastic - rapid-rs is built on it! But Axum is intentionally minimal. You still wire up:

  • Configuration loading
  • Database connections
  • Migrations
  • Validation
  • Error handling
  • OpenAPI generation
  • Logging
  • CORS
  • Authentication
  • Testing utilities

rapid-rs gives you all of this out of the box.

Documentation

License

Licensed under either of:

at your option.

Credits

Built by Ashish Sharda

Standing on the shoulders of giants:

  • Axum - The excellent web framework
  • sqlx - Async SQL toolkit
  • FastAPI - Inspiration for developer experience
  • Spring Boot - Inspiration for conventions

Star โญ this repo if you find it useful!

Report Bug ยท Request Feature ยท Documentation