Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Kerniq Server
A lightweight, asynchronous web framework for Rust: Flask-like simplicity on top of Axum, Tower, Hyper and Tokio.
Simple by default. Powerful when needed. Extensible by design.
use *;
async
Why Kerniq?
Axum is an excellent foundation, but a production service needs more than a router: consistent error responses, ordered middleware that cannot silently skip routes, configuration, graceful shutdown with bounded drain, connection and concurrency limits, background tasks, and a project layout. Kerniq packages those decisions behind a small, Flask-like API without replacing anything underneath:
- Every Kerniq handler is an Axum handler, every middleware is Tower
middleware, and every app converts to an
axum::Router. - No second routing engine, no custom executor, no HTTP implementation.
- No mandatory database, ORM or authentication provider.
Kerniq suits REST APIs, microservices, fintech backends, AI inference endpoints, WebSocket services and internal enterprise systems.
Installation
Kerniq requires Rust 1.88+.
[]
= "0.1"
= { = "1", = ["macros", "rt-multi-thread"] }
= { = "1", = ["derive"] }
Kerniq 0.1.0 is not yet published to crates.io. Until it is, depend on a checkout:
kerniq-server = { path = "../kerniq-server/crates/kerniq-server" }, or usekerniq new --kerniq-path <checkout>.
A taste of the API
use Arc;
use Duration;
use *;
use ;
async
async
async
async
Malformed input, unknown routes, timeouts and handler errors all share one JSON error format:
Status codes and errors
Error statuses (400, 404, 409, …): return an Error from a handler that
returns Result<T>. Each common status has a constructor, and the builder
methods let you customize the response:
use *;
use Deserialize;
async
// Any other status:
Constructors: bad_request (400), unauthorized (401), forbidden (403),
not_found (404), method_not_allowed (405), timeout (408), conflict
(409), payload_too_large (413), unsupported_media_type (415),
unprocessable (422), validation (422), too_many_requests (429),
internal (500), service_unavailable (503). .with_header(...) adds
headers such as Retry-After.
ResultExt and OptionExt make ? convenient:
use *;
Success or arbitrary statuses: return StatusCode, or a (StatusCode, body)
tuple, optionally with headers in the middle. Created(body) (201) and
NoContent (204) are shortcuts.
use *;
async
async
async
Use Error for failures so clients always get the JSON envelope, and status
tuples for everything else. See Handlers, responses and
errors for the full guide, and
examples/error-handling for a runnable version.
Databases and message brokers
Kerniq does not wrap any database or broker client: use the crate you
already know (sqlx, redis, mongodb, rdkafka, lapin, …). Connect
at startup, share the client through state, run consumers as background
tasks that stop on shutdown, and close connections after run returns:
use *;
use ;
async
async
Databases and message brokers has complete examples
for PostgreSQL/MySQL/SQLite (sqlx), Redis (commands and pub/sub), MongoDB,
Kafka (producer and consumer) and RabbitMQ (publisher and consumer), plus
error mapping, health checks, pool sizing and testing.
Features
| Area | What you get |
|---|---|
| Routing | get/post/put/patch/delete/options/head/any/on, {id} or :id params, prefixes, groups, mounting, nested fallbacks |
| Extractors | Path, Query, Json, State, Header<T>, Body, plus any Axum extractor |
| Errors | One Error type, JSON envelope, internal details logged and never leaked, domain errors via From |
| State | Typed App<S>, FromRef sub-states, no globals |
| Middleware | Ordered (first declared = outermost), applies to all routes, Tower-native, app- or router-scoped |
| Built-in middleware | Logger, RequestId, Timeout, BodyLimit, ConcurrencyLimit, Cors, Compression, SecurityHeaders, RateLimit, Auth, Metrics (Prometheus) |
| Lifecycle | Graceful shutdown (SIGINT/SIGTERM), bounded drain, connection limits, background tasks, run / run_blocking |
| Configuration | Builder, KERNIQ_* environment variables, TOML files |
| Optional | WebSockets, OpenAPI + Swagger UI (Utoipa), validation (validator), #[authorize] role/permission checks |
| Interop | into_axum_router, mount_axum, native Axum handlers, extractors and layers |
| CLI | kerniq new (basic, rest, modular, production), dev (auto-restart), build, check, test |
Cargo features: json and tracing (default), cors, compression,
websocket, openapi, validation, config-file, macros, full. With
default-features = false the dependency tree is about half the size of the
full one.
CLI
Every template compiles, passes kerniq check, and passes its own tests
immediately after generation.
Using Kerniq with Claude Code
skills/kerniq-server/SKILL.md is a
Claude Code skill that
teaches Claude how to build services with Kerniq: project templates and
layout, routing, errors, state, middleware order, authentication and
authorization, configuration, databases and brokers, and testing. Install it
for all your projects, or for a single one:
Claude loads it automatically when you work on a Kerniq service, for example "create an orders service with Kerniq" or "add an admin-only endpoint".
Architecture
kerniq-server ── App, prelude, re-exports (the crate you depend on)
├── kerniq-core Error model, ServerConfig
├── kerniq-http Extractors and responses
├── kerniq-routing Router, groups, Middleware composition
├── kerniq-middleware Production middleware (tower / tower-http)
├── kerniq-runtime Accept loop, graceful shutdown, background tasks
└── kerniq-openapi Utoipa documents + Swagger UI (optional)
kerniq-cli Independent scaffolding tool
See docs/architecture.md for the design decisions, including where the specification was adapted to Rust's type system.
Performance
Kerniq adds a thin layer over Axum, and its overhead is measured, not
assumed. On the benchmark machine (Apple M3 Pro), Kerniq matched native Axum
on allocations and dispatch time for routing, JSON and state, and its fused
middleware stack allocated less than the equivalent tower-http stack. Over
real HTTP it was within a few percent of axum::serve. The one measurable
default cost, slow-header protection (about 3.5% on a trivial endpoint), is
documented and can be switched off. Methodology, raw results and limitations
are in docs/performance.md. Run
benches/run-http.sh on your own hardware.
Documentation
- Getting started — installation, first app, CLI
- Routing
- Handlers, responses and errors
- Extractors (including validation)
- Shared state
- Middleware (including custom middleware)
- Authorization (roles and permissions)
- Axum and Tower interoperability
- Runtime, lifecycle and graceful shutdown
- WebSockets
- Configuration
- Databases and message brokers (PostgreSQL, MySQL, SQLite, Redis, MongoDB, Kafka, RabbitMQ)
- OpenAPI
- Performance and benchmarking
- Architecture
- Migration guide — upgrading across breaking releases
- Changelog
Runnable examples live in examples/: hello-world,
rest-api, shared-state, route-groups, middleware,
custom-middleware, error-handling, axum-integration, websocket,
graceful-shutdown, openapi, validation and run-blocking:
Every Rust snippet in this README and in docs/ is compiled as a doctest,
except the third-party integration examples (marked ignore), which need
crates Kerniq does not depend on.
Contributing
See CONTRIBUTING.md. Every change must pass:
License
Licensed under either of Apache License 2.0 or MIT license, at your option.