# fnroute
`fnroute` is a small function router with axum-style handler extraction.
It is not an HTTP framework. It is a general-purpose route dispatcher that can
register async and sync functions with different parameter lists, then extract
those parameters from a route context.
`fnroute` is zero-dependency and supports `no_std` with `alloc`.
```rust
use fnroute::{Input, Param, RouteContext, Router, State};
#[derive(Clone)]
struct AppState {
name: String,
}
#[derive(Clone)]
struct Payload {
action: String,
}
async fn user(
Param(id): Param<u64>,
Input(payload): Input<Payload>,
State(state): State<AppState>,
) -> String {
format!("{} user {id} {}", state.name, payload.action)
}
# async fn example() {
let app = Router::<String>::new()
.with_state(AppState {
name: "demo".to_string(),
})
.route("users/:id", user);
let output = app
.call_with(RouteContext::new("users/42").input(Payload {
action: "saved".to_string(),
}))
.await
.unwrap();
assert_eq!(output, "demo user 42 saved");
# }
```
## Core Idea
- `Router<R, S>` stores routes and fixes the final return type `R`.
- `FromRoute<S>` lets each parameter type extract itself from `RouteContext`.
- `route(...)` registers async handlers.
- `route_sync(...)` registers sync handlers.
Handler implementations are generated up to 16 parameters.