Crate worker_router

Source
Expand description

HTTP router for Cloudflare Workers

Example using the worker:

struct ServerState {}

async fn get_hello(_req: Request, _state: Arc<ServerState>) -> Result<Response> {
  ResponseBuilder::new().ok("hello")
}

#[event(fetch)]
async fn fetch(req: Request, _env: Env, _ctx: Context) -> Result<Response> {
  let state = Arc::new(ServerState {});
  let router = router::Router::new_with_state(state).get(router::path("/hello")?, get_hello);

  router.run(req).await
}

Structs§

Pattern
Route pattern
Router
HTTP router

Functions§

path
Construct a route pattern using a URL path Examples:

Type Aliases§

ResponseFuture