#axum #routing #handler #macro #typed

axum-typed-routing

Typed routing macros for axum

5 releases

0.2.1 Feb 23, 2024
0.2.0 Feb 10, 2024
0.1.2 Jan 5, 2024
0.1.1 Jan 5, 2024
0.1.0 Jan 5, 2024

#78 in #typed

Download history 35/week @ 2024-11-17 59/week @ 2024-11-24 65/week @ 2024-12-01 32/week @ 2024-12-08 88/week @ 2024-12-15 1/week @ 2024-12-22 10/week @ 2024-12-29 21/week @ 2025-01-05 35/week @ 2025-01-12 22/week @ 2025-01-19 30/week @ 2025-01-26 60/week @ 2025-02-02 11/week @ 2025-02-09 93/week @ 2025-02-16 88/week @ 2025-02-23 63/week @ 2025-03-02

257 downloads per month
Used in axum-controller

MIT/Apache

18KB
155 lines

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.


lib.rs:

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.

Dependencies

~5–13MB
~130K SLoC