6 releases

0.3.0 Jun 1, 2025
0.2.1 Feb 23, 2024
0.1.2 Jan 5, 2024

#970 in Rust patterns

Download history 87/week @ 2025-02-18 93/week @ 2025-02-25 127/week @ 2025-03-04 78/week @ 2025-03-11 277/week @ 2025-03-18 106/week @ 2025-03-25 8/week @ 2025-04-01 115/week @ 2025-04-08 17/week @ 2025-04-15 56/week @ 2025-04-22 30/week @ 2025-04-29 24/week @ 2025-05-06 13/week @ 2025-05-13 1/week @ 2025-05-20 123/week @ 2025-05-27 21/week @ 2025-06-03

164 downloads per month
Used in axum-controller

MIT/Apache

19KB
156 lines

Basic usage

The following example demonstrates the basic usage of the library. On top of any regular handler, you can add the route macro to create a typed route. Any path- or query-parameters in the url will be type-checked at compile-time, and properly extracted into the handler.

The following example shows how the path parameter id, and query parameters amount and offset are type-checked and extracted into the handler.

Some valid url's as get-methods are:

  • /item/1?amount=2&offset=3
  • /item/1?amount=2
  • /item/1?offset=3
  • /item/500

By marking the amount and offset parameters as Option<T>, they become optional.

Example with aide

When the aide feature is enabled, it's possible to automatically generate OpenAPI documentation for the routes. The api_route macro is used in place of the route macro.

Please read the aide documentation for more information on usage.


Crates.io Documentation

Axum-typed-routing

A library for creating statically-typed handlers in axum using macros, similar to Rocket with OpenAPI support using aide.

See the docs for more information.

Dependencies

~6–14MB
~150K SLoC