# ๐ rapid-rs
> **Zero-config, batteries-included web framework for Rust**
> FastAPI meets Spring Boot, powered by Axum
[](https://crates.io/crates/rapid-rs)
[](https://docs.rs/rapid-rs)
[](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
```rust
// Database with auto-migrations
use rapid_rs::database::{connect_and_migrate, MigrationConfig};
let pool = connect_and_migrate(
"postgres://localhost/myapp",
MigrationConfig::default()
).await?;
```
```rust
// 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 โ](https://github.com/ashishjsharda/rapid-rs/blob/main/CHANGELOG.md)
---
## 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
```bash
cargo install rapid-rs-cli
```
### Create Your First API
```bash
# 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
```rust
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
| 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
```bash
# Create project with template
# 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:
```rust
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:
```bash
cargo install sqlx-cli
sqlx migrate add create_users
```
[Learn more about migrations โ](https://github.com/ashishjsharda/rapid-rs/blob/main/MIGRATIONS.md)
## Testing Your API
Built-in testing utilities make API testing a breeze:
```rust
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 โ](https://github.com/ashishjsharda/rapid-rs/blob/main/TESTING.md)
## Authentication
Complete JWT authentication system included:
```rust
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 โ](https://github.com/ashishjsharda/rapid-rs/blob/main/AUTH.md)
## Configuration
Configuration loads from multiple sources:
```toml
# config/default.toml
[server]
host = "0.0.0.0"
port = 8080
[database]
url = "postgres://localhost/mydb"
```
Override with environment variables:
```bash
APP__SERVER__PORT=8080 cargo run
AUTH_JWT_SECRET="your-secret-key" cargo run
```
## Examples
Check out the [examples](https://github.com/ashishjsharda/rapid-rs/tree/main/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
- [x] Core framework with auto-configuration
- [x] Request validation
- [x] OpenAPI generation
- [x] CLI tool
- [x] Hot reload
### Phase 2 โ
Complete (v0.3.0)
- [x] Authentication & Authorization
- [x] Database migrations management
- [x] Testing utilities
- [x] GraphQL template
- [x] 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
```bash
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 โ](https://github.com/ashishjsharda/rapid-rs/blob/main/CONTRIBUTING.md)
## 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
- ๐ [API Documentation](https://docs.rs/rapid-rs)
- ๐ [Authentication Guide](AUTH.md)
- ๐๏ธ [Migrations Guide](MIGRATIONS.md)
- ๐งช [Testing Guide](TESTING.md)
- ๐ค [Contributing Guide](CONTRIBUTING.md)
- ๐ [Changelog](CHANGELOG.md)
## License
Licensed under either of:
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE))
- MIT license ([LICENSE-MIT](LICENSE-MIT))
at your option.
## Credits
Built by [Ashish Sharda](https://github.com/ashishjsharda)
Standing on the shoulders of giants:
- [Axum](https://github.com/tokio-rs/axum) - The excellent web framework
- [sqlx](https://github.com/launchbadge/sqlx) - Async SQL toolkit
- [FastAPI](https://fastapi.tiangolo.com/) - Inspiration for developer experience
- [Spring Boot](https://spring.io/projects/spring-boot) - Inspiration for conventions
---
**Star โญ this repo if you find it useful!**
[Report Bug](https://github.com/ashishjsharda/rapid-rs/issues) ยท [Request Feature](https://github.com/ashishjsharda/rapid-rs/issues) ยท [Documentation](https://docs.rs/rapid-rs)