UNPKG

cassava

Version:
57 lines (56 loc) 2.28 kB
/// <reference types="node" /> import { Route } from "./Route"; import { RouterEvent } from "../RouterEvent"; import { RouterResponse } from "../RouterResponse"; export declare class BuildableRoute implements Route, RouteBuilder { private settings; matches(evt: RouterEvent): boolean; handle(evt: RouterEvent): Promise<RouterResponse> | null; postProcess(evt: RouterEvent, resp: RouterResponse, handlingRoutes: Route[]): Promise<RouterResponse> | null; path(path: string | RegExp): this; method(method: string): this; serializers(serializers: { [mimeType: string]: (body: any) => Promise<string> | string; }): this; handler(handler: (evt: RouterEvent) => Promise<RouterResponse>): this; postProcessor(postProcessor: (evt: RouterEvent, resp: RouterResponse, handlingRoutes: Route[]) => Promise<RouterResponse>): this; } export interface RouteBuilder { /** * Match requests with the given path. */ path(path: string | RegExp): this; /** * Match requests for the given method. */ method(method: string): this; /** * Match requests for clients than can accept one of the given mime-types * and use the given serializer on the response body. The serializer will be * called with the body if the handler returns a response. The serializer * must return a string or Buffer, or Promise of such. * * eg: * ``` * serializers({ * "application/json": cassava.serializers.jsonSerializer, * "text/plain": body => body.toString() * }) * ``` * * @param serializers a map of mime-type to serializer function */ serializers(serializers: { [mimeType: string]: (body: any) => Promise<string | Buffer> | string | Buffer; }): this; /** * Set the handler for this Route. * @see routes.Route.handle */ handler(handler: (evt: RouterEvent) => Promise<RouterResponse | null | void> | RouterResponse | null | void): this; /** * Set the post processor for this Route. * @see routes.Route.postProcess */ postProcessor(postProcessor: (evt: RouterEvent, resp: RouterResponse, handlingRoutes: Route[]) => Promise<RouterResponse | null | void> | RouterResponse | null | void): this; }