worker_route

Attribute Macro route

Source
#[route]
Expand description

A macro that creates route handler with multiple methods.

§Usage

#[route("path", method = "method", cors = "cors", lazy_cors = "lazy_cors", wrap)]

§Attributes

  • "path": Worker’s path.
  • method: An array of methods or a method in string literal.
  • Option<cors>: Wrap a struct that implements worker_route::MwService.
  • Option<lazy_cors>: Wrap a lazy initialized Cors.
  • Option<wrap>: Register an options handler with the provided cors. Defaults to None.

§Examples

use worker::{Result, Request, RouteContext, Response};
use worker_route::route;
 
#[route("/path", method = "get", method = "post")]
async fn foo(req: Request, ctx: RouteContext<()>) -> Result<Response> {
    Response::empty()
}