Expand description
§Kerniq Server
A lightweight, asynchronous web framework for Rust: the approachability of Flask on top of Axum, Tower, Hyper and Tokio.
use kerniq_server::prelude::*;
#[tokio::main]
async fn main() -> Result<()> {
App::new()
.get("/", || async { "Hello from Kerniq" })
.run("127.0.0.1:3000")
.await
}§What Kerniq adds, and what it reuses
Kerniq is a thin ergonomic layer. Routing, extraction and HTTP are Axum’s; middleware is Tower’s; the protocol is Hyper’s; execution is Tokio’s. Kerniq contributes:
- the
Appbuilder: Flask-style route registration, typed state, configuration, lifecycle (graceful shutdown, background tasks, connection and concurrency limits) in one place, Routerwith prefixes, groups and mounting,- middleware that applies to every route regardless of declaration order, with first-declared-is-outermost ordering,
- one JSON error envelope for application errors, malformed input, 404/405, timeouts, rate limiting and authentication failures,
- production middleware (logging, request IDs, CORS, compression, timeouts, rate limiting, auth extension points, metrics),
- optional OpenAPI, validation and WebSocket support.
Handlers are plain Axum handlers, and the app converts to an
axum::Router with App::into_axum_router, so the Axum and Tower
ecosystems stay fully available.
§Crate features
| Feature | Default | Enables |
|---|---|---|
json | ✓ | Json<T>, Created<T> |
tracing | ✓ | Logger middleware |
cors | Cors middleware | |
compression | Compression middleware | |
websocket | extract::ws | |
openapi | openapi module (Utoipa + Swagger UI) | |
validation | ValidatedJson, ValidatedQuery | |
config-file | ServerConfig::from_file (TOML) | |
macros | authorize attribute for role/permission checks | |
full | all of the above | |
observability | App::observability, observability module | |
observability-metrics | OpenTelemetry metrics, HTTP metrics | |
observability-logs | JSON / pretty console logs, log export | |
observability-tracing | distributed tracing, W3C propagation | |
otlp / otlp-tls | OTLP export to a Collector or backend | |
prometheus | Prometheus scrape endpoint | |
runtime-metrics | Tokio and process metrics | |
full-observability | all observability features except otlp-tls |
Re-exports§
Modules§
- config
- Server configuration. See
ServerConfig. - error
- The error model. See
Error. - extract
- Request extractors.
- middleware
- Middleware: the composition traits and the built-in middleware.
- observability
observability - Kerniq Observe: metrics, logs and traces (feature
observability). SeeApp::observability. - openapi
openapi - OpenAPI documents and Swagger UI (feature
openapi). - prelude
- Everything most applications need:
use kerniq_server::prelude::*; - response
- Response types.
- routing
- Routers, groups and method routers.
- runtime
- Server lifecycle: shutdown handles, background tasks and runtime helpers.
Structs§
- App
- A Kerniq application: routes, state, middleware, configuration and lifecycle in one builder.
- Error
- The framework error type.
Type Aliases§
Attribute Macros§
- authorize
macros - Protects a handler with a role or permission rule, in the spirit of
Spring’s
@PreAuthorize.