diode-http
HTTP services for the diode
dependency-injection framework, built on axum.
It provides HTTP servers, attribute macros for declaring routers, dependency-
injected middleware, and ready-made health endpoints.
[]
= "0.2"
= "0.3"
= "0.3"
Example
Declare a router with the #[router] / #[route] macros, register it, and run
the server:
use ;
use ;
use ;
;
async
Servers
Two independent servers are available, each running as a daemon and shutting down gracefully:
- Public -
HttpServerPlugin, configured from thehttp_serversection. - Control -
ControlServerPlugin, configured from thecontrol_serversection. A separate, typically internal, plane for operational endpoints; it hosts the health-check registry and aHealthClientpointed at its own/health.
Routers
A router is any type implementing RouterBuilder. The easiest way is the
#[router] attribute on an impl block, with #[route(method, path = "..")]
on each handler. Register routers either as a concrete instance or resolved from
the DI container:
| public server | control server | |
|---|---|---|
| instance | add_router(value) |
add_control_router(value) |
| DI service | add_router_service::<T>() |
add_control_router_service::<T>() |
Each type may back at most one router; registering the same type twice panics.
has_router / has_router_service (and the control-server equivalents) let you
check first.
Middleware
Middleware implements the Middleware trait. Register a concrete instance with
add_middleware(value), or a DI-built middleware (one that holds injected
dependencies) with add_middleware_service::<T>(). Attach it with the macro
attributes:
Ordering: within a middleware = [A, B] list the first entry is outermost (runs
first on the request, last on the response), and router-level middleware wraps
route-level middleware.
Health checks
Implement HealthCheck and register it with add_health_check(..) /
add_health_check_service::<T>(). Add HealthRouter to the control server to
expose GET /health, which runs every registered check and returns 200
healthy or 500 with a JSON error naming the first failing check. PingHandler
exposes a trivial GET /ping, and HealthClient probes a /health endpoint
(useful for readiness waits).
Features
macros(default) - the#[router]/#[route]attribute macros.
License
Licensed under either of MIT or Apache-2.0 at your option.