Kasi (kasi-jb)
Kasi is an async, macro-driven web and microservice framework for Rust built on Hyper 1.x and Tokio. It combines compile-time route and schema generation with sequential request extractors, RFC 7807 error responses, OpenID Connect JWT verification, static file serving, multipart uploads, and zero-boilerplate OpenAPI 3.1 documentation.
Installation & CLI Scaffolder
Scaffold a New Project with kasi-cli
Install the CLI scaffolder and generate a ready-to-run service in seconds:
Add kasi-jb to an Existing Project
Enable optional feature flags as needed in Cargo.toml:
[]
# Default enables both `postgres` (SeaORM + SQLx) and `templates` (MiniJinja)
= "0.5.1"
# Or opt into only what you need:
# kasi-jb = { version = "0.5.1", default-features = false, features = ["templates", "graphql"] }
Quick Start
use *;
async
async
Core Features
1. Declarative Routing & Regex Path Constraints
Use #[endpoint(METHOD, "/path")] to define async handlers and mount them directly with .route(fn_name). Endpoints can return Result<T, E> or any IntoResponse type directly (String, &'static str, JsonValue, Html). Path parameters support inline regular expressions and deserialize into primitives or structs via Path<T>.
async
async
async
2. Sequential Request Extractors & Validation
Extractors consume and thread request ownership sequentially, allowing multiple extractors per handler without borrow or move conflicts:
Path<T>: Extracts URL path parameters.Query<T>: Deserializes URL query strings.Json<T>: Deserializes JSON request bodies.ValidatedJson<T>: Deserializes JSON and runs#[derive(Validate)]rules automatically, returning an RFC 7807400 Bad Requeston failure.Multipart: Parsesmultipart/form-datatext fields and binary file uploads (UploadedFile).Cookies: Extracts parsedCookieheaders into a key-value map.Extension<T>: Clones shared application state registered via.extension(...).RequestContext: Provides the request URI, HTTP method, and activetrace_id.
async
3. Multipart File Uploads
Extract text fields and uploaded files directly with Multipart:
async
4. Static File Serving & MiniJinja Templates
Serve static assets (CSS, JS, images) safely with path-traversal protection via .serve_dir(url_prefix, dir), and render server-side HTML templates with TemplateEngine (feature = "templates").
async
// Mount static files and templates on ApplicationBuilder:
// app.extension(TemplateEngine::from_dir("templates"))
// .serve_dir("/static", "public")
5. Cookie & Session Management
Read incoming browser cookies via Cookies and issue HttpOnly / SameSite cookies using Cookie:
async
async
6. Polymorphic Responses & RFC 7807 Problem Details
Derive IntoResponse on structs for 200 OK JSON responses, and on enums for standardized application/problem+json error envelopes.
7. Auto-Generated OpenAPI 3.1 Specs & Swagger UI
Annotate endpoints with #[response(...)] and derive Schema on your models. Kasi builds the OpenAPI 3.1.0 specification at startup and serves it automatically:
- OpenAPI JSON:
GET /openapi.json - Interactive Swagger UI:
GET /docs
async
// Register schemas on ApplicationBuilder:
// app.register_schema::<UserDto>().route(fetch_user)
8. OpenID Connect (OIDC) JWT Security
Protect routes declaratively with #[security(...)]. OidcConfig::discover fetches and caches your identity provider's JWKS (Keycloak, Auth0, Okta, Google) at startup for fast local signature verification.
async
9. Database Pools & Automatic Transactions (feature = "postgres")
Inject SeaORM (Db) or SQLx (DbPool) connections via .extension(...), or use the Tx extractor to open a SeaORM transaction that commits automatically on Ok and rolls back on Err.
async
10. Modular Route Nesting & Built-In Middleware
Group endpoints under URL prefixes with isolated middleware using Module, and attach global middleware layers to ApplicationBuilder:
TracingMiddleware::new()/TracingMiddleware::json(): PropagatesX-Request-Idheaders and logs request latency.RateLimitMiddleware::new(max_requests, window): Fixed-window per-client throttling withX-RateLimit-*headers and429responses.CorsMiddleware: Configurable cross-origin resource sharing.
let inventory = new.route;
let api_v1 = new
.wrap
.nest_with_docs;
let app = builder
.middleware
.middleware
.middleware
.register_module
.build
.await?;
11. Bidirectional WebSockets
Upgrade HTTP GET connections into full-duplex WebSockets with WebSocketUpgrade:
async
12. Background Task Scheduling
Schedule recurring interval workers on ApplicationBuilder (automatically stopped during graceful shutdown) or extract Extension<TaskScheduler> in handlers to spawn background jobs:
let app = builder
.schedule_task
.route
.build
.await?;
13. Server-Sent Events (Sse)
Stream real-time server events over text/event-stream using Sse and SseEvent:
async
14. Response Compression & Prometheus Observability
Enable automatic Gzip response compression and mount built-in GET /healthz and GET /metrics endpoints with a single builder call:
let app = builder
.with_observability // Mounts GET /healthz and GET /metrics
.middleware
.route
.build
.await?;
Workspace Crates
| Crate | Purpose |
|---|---|
kasi-jb |
Umbrella facade and prelude re-exporting the full framework API. |
kasi-core |
Hyper runtime, regex router, extractors, static files, cookies, middleware, templates, and OpenAPI generator. |
kasi-macros |
Procedural macros (#[endpoint], #[main], #[derive(IntoResponse, Validate, Schema)]). |
kasi-security |
OIDC discovery client, JWKS caching, and AuthContext RBAC/scope guards. |
kasi-cli |
Command-line project scaffolder (kasi new <project-name>). |
License
MIT License — Copyright (c) 2026 Justice Sam.