kegani 0.1.1

A developer-friendly, ergonomic, production-ready Rust web framework
Documentation

Kegani - Rust Web Framework

A developer-friendly, ergonomic, production-ready Rust web framework built on Actix-web.

Features

  • Fast HTTP Server: Built on Actix-web for high performance
  • Type-safe Routing: Express/Gin-style route definitions with procedural macros
  • Middleware System: Logging, CORS, Tracing, Timeout, Rate Limiting
  • Session Management: In-memory session storage
  • JWT Authentication: Built-in JWT support with Claims
  • Caching: Redis integration
  • Metrics: Prometheus-compatible metrics collection
  • OpenAPI Support: Swagger UI and ReDoc integration
  • Database: SQLx integration with PostgreSQL support
  • Repository Pattern: Clean data access layer
  • Service Layer: Dependency injection for business logic

Quick Start

use kegani::prelude::*;

#[tokio::main]
async fn main() -> std::io::Result<()> {
    App::new()
        .host("127.0.0.1")
        .port(8080)
        .run()
        .await
}

Route Macros

use kegani::prelude::*;

#[get("/api/users/{id}")]
async fn get_user(Path(id): Path<String>) -> Result<Json<User>, AppError> {
    // ...
}

#[post("/api/users")]
async fn create_user(Json(user): Json<CreateUser>) -> Result<Json<User>, AppError> {
    // ...
}

Response Helpers

use kegani::prelude::*;

// JSON response
Ok(Json::new(data))

// Created status
Ok(Json::created(data))

// Named status codes
Err(AppError::NotFound)

// Custom response
Response::new()
    .status(StatusCode::OK)
    .header("X-Custom", "value")
    .json(&data)

Middleware

App::new()
    .wrap(Logger::new())
    .wrap(Cors::permissive())
    .wrap(Tracing::new())
    .wrap(Timeout::new(Duration::from_secs(30)))

Modules

Module Description
app Application builder
error Unified error handling
route Route extractors (Path, Query, State)
controller Response types (Json, Status, Response)
middleware Logger, Cors, Tracing, Timeout, RateLimit
config Configuration management
health Health check endpoints
metrics Metrics collection
auth JWT authentication
cache Redis caching
db Database connection pool
repository Repository pattern
service Service layer with DI
openapi OpenAPI documentation
client API client generator

Testing

# Run all tests
cargo test --all

# Run performance tests
cargo test --test performance_tests

Performance Benchmarks

  • JSON Serialization: 10,000 ops in < 100ms
  • HashMap Operations: 100,000 lookups in < 50ms
  • UUID Generation: 10,000 ops in < 100ms

Configuration

Load configuration from YAML and environment variables:

let config = AppConfig::load()?;

// Override with environment variables
// APP_HOST, APP_PORT, DATABASE_URL, REDIS_URL, LOG_LEVEL

License

MIT OR Apache-2.0