Attribute Macro tusk_rs::route

source ·
#[route]
Expand description

This macro is used to define a route. It takes in a request type and a route name.

The arguments are: #[route(Method Path {: secure_fn (optional)})]

Valild methods are:

  • Get
  • Post
  • Put
  • Delete
  • Patch

If this route is registered using the Server::module function, the path provided will be prepended to the path provided in the macro.

This macro should be applied to a function with arguments for:

  • [Request]
  • [DatabaseConnection]
  • T, where T is the type provided by treatment function. for more information, see the tusk_rs::Server documentation

It should return a Result<Response, RouteError>.

The route macro all supports security middleware by adding : your_secure_fn to the end of the macro. The secure function should be an async function with arguments for:

  • [Request]
  • [DatabaseConnection]
  • T and should return Result<(Request, DatabaseConnection, T), RouteError>. Returning an Ok value allows the route to continue, while returning an Err value will return the error to the client.