Skip to main content

Crate kerniq_server

Crate kerniq_server 

Source
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 App builder: Flask-style route registration, typed state, configuration, lifecycle (graceful shutdown, background tasks, connection and concurrency limits) in one place,
  • Router with 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

FeatureDefaultEnables
json✓Json<T>, Created<T>
tracing✓Logger middleware
corsCors middleware
compressionCompression middleware
websocketextract::ws
openapiopenapi module (Utoipa + Swagger UI)
validationValidatedJson, ValidatedQuery
config-fileServerConfig::from_file (TOML)
macrosauthorize attribute for role/permission checks
fullall of the above
observabilityApp::observability, observability module
observability-metricsOpenTelemetry metrics, HTTP metrics
observability-logsJSON / pretty console logs, log export
observability-tracingdistributed tracing, W3C propagation
otlp / otlp-tlsOTLP export to a Collector or backend
prometheusPrometheus scrape endpoint
runtime-metricsTokio and process metrics
full-observabilityall observability features except otlp-tls

Re-exports§

pub use axum;
pub use http;
pub use tower;

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.
observabilityobservability
Kerniq Observe: metrics, logs and traces (feature observability). See App::observability.
openapiopenapi
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§

Result
A Result whose error type defaults to the Kerniq Error.

Attribute Macros§

authorizemacros
Protects a handler with a role or permission rule, in the spirit of Spring’s @PreAuthorize.