serwist
Version:
A Swiss Army knife for service workers.
33 lines • 1.31 kB
TypeScript
import type { HTTPMethod } from "./constants.js";
import type { RouteHandler, RouteHandlerObject, RouteMatchCallback } from "./types.js";
/**
* A `Route` consists of a pair of callback functions, `match` and `handler`.
* The `match` callback determines if a route should be used to handle a
* request by returning a truthy value if it can. The `handler` callback
* is called when the route matches and should return a promise that resolves
* to a response.
*/
export declare class Route {
handler: RouteHandlerObject;
match: RouteMatchCallback;
method: HTTPMethod;
catchHandler?: RouteHandlerObject;
/**
* Constructor for Route class.
*
* @param match A callback function that determines whether the
* route matches a given `fetch` event by returning a truthy value.
* @param handler A callback function that returns a `Promise` resolving
* to a `Response`.
* @param method The HTTP method to match the route against. Defaults
* to `GET`.
*/
constructor(match: RouteMatchCallback, handler: RouteHandler, method?: HTTPMethod);
/**
*
* @param handler A callback function that returns a Promise resolving
* to a Response.
*/
setCatchHandler(handler: RouteHandler): void;
}
//# sourceMappingURL=Route.d.ts.map