[][src]Attribute Macro actix_web::route

#[route]

Creates resource handler, allowing multiple HTTP method guards.

Syntax

#[route("path", method="HTTP_METHOD"[, attributes])]

Attributes

  • "path" - Raw literal string with path for which to register handler.
  • method="HTTP_METHOD" - Registers HTTP method to provide guard for. Upper-case string, "GET", "POST" for example.
  • guard="function_name" - Registers function as guard using actix_web::guard::fn_guard
  • wrap="Middleware" - Registers a resource middleware.

Notes

Function name can be specified as any expression that is going to be accessible to the generate code, e.g my_guard or my_module::my_guard.

Example

#[route("/test", method="GET", method="HEAD")]
async fn example() -> HttpResponse {
    HttpResponse::Ok().finish()
}