axum_rh
Axum router helper helps you build an API simply by using macros to define the router and all endpoints.
Install
cargo add axum-rh
Middlewares
All middlewares are optional and can be overriden by your own
Logging
A simple logger middleware that can also send logs into betterstack (with the async feature) format request logs ```
Sessions
Use Redis storage to
Auth
A default JWT authentication middleware
How to:
Declare router
// base RouterHelper derive macros
// the router_config define the state type (here is an empty state), Health and
// Sample are routers definitions
;
Use states
;
Declare Endpoints
To declare an endpoint two macros are needed. The first one will be applied on the implementation of the module definition.
;
As you can see here it can take an optional argument base_path which will default to / if not set.
The second one will be applied on each function definition under the struct impl
;
get
Define a get endpoint
post
Define a post endpoint
put
Define a put endpoint
delete
Define a delete endpoint
Return values
The APIResponse struct define a default response type for our enpoints. You can use it or define your own response type as long as it implements into_response