auto_route
auto_route adds Spring-style route attributes to Axum and integrates controller construction with auto-di.
You write #[controller], #[get], and #[post]; the crate generates ordinary Axum routes and discovers them automatically at startup.
Installation
[]
= "0.6"
= "0.1"
= "0.8"
= { = "1", = ["full"] }
DI-managed controller
use Arc;
use singleton;
use controller;
use ;
;
/:id is accepted for convenience and converted to Axum 0.8's /{id} syntax.
Standalone route
No controller is required for a normal function:
use get;
async
Module route group
An inline module can provide a shared base path without a controller object:
use controller;
Only inline modules are supported. #[controller] mod routes; cannot be inspected by a procedural macro.
Start the server
Call auto_route::routes() once while constructing the application:
use TcpListener;
async
Every controller and standalone route submits a small factory to a compile-time inventory registry. At startup, auto_route resolves controller singletons through auto-di, builds their Axum routers, and merges them into one application router. Macros do not run for each request.
Supported method attributes: get, post, put, delete, patch, options, and head.
License
MIT