cassava
Version:
AWS API Gateway Router
51 lines (50 loc) • 2.15 kB
TypeScript
import * as awslambda from "aws-lambda";
import { Route, RouteBuilder } from "./routes";
import { ProxyEvent } from "./ProxyEvent";
import { ProxyResponse, ProxyResponseCallback } from "./ProxyResponse";
import { RouterResponse } from "./RouterResponse";
export declare class Router {
/**
* Both node 4.3 and 6.10 use the callback parameter to return a result.
* The ability to create new functions using Node.js 4.3 will be disabled July 31, 2018.
* Code updates to existing functions using Node.js v4.3 will be disabled on October 31, 2018.
* When the ability to update code in node 6.10 functions is disabled this can be removed.
*/
useLegacyCallbackHandler: boolean;
/**
* Routes that will be tested against in order.
*/
readonly routes: Route[];
/**
* The default route that will be matched if no other routes matched.
*
* The default implementation is to return a 404 response.
*/
defaultRoute: Route;
/**
* The handler that will be called when non-RestErrors are thrown.
* The handler can return nothing, a RouterResponse, or a Promise that resolves
* such. If a RouterResponse or Promise of RouterResponse is returned that will
* be the response used.
*
* The handler will be called with: the Error thrown, the input ProxyEvent that
* caused the error and the Lambda context.
*
* The default implementation is to log the error.
*/
errorHandler: (err: Error, evt: ProxyEvent, ctx: awslambda.Context) => Promise<RouterResponse | null | void> | RouterResponse | null | void;
/**
* Start a BuildableRoute with the given string or regex path.
*/
route(path?: string | RegExp): RouteBuilder;
/**
* Add a custom Route.
*/
route<T extends Route>(route: T): T;
getLambdaHandler(): (evt: ProxyEvent, ctx: awslambda.Context, callback: ProxyResponseCallback) => void | Promise<ProxyResponse>;
private routeProxyEvent;
private proxyEventToRouterEvent;
private proxyPathToRouterPath;
private errorToRouterResponse;
private routerResponseToProxyResponse;
}