import { HttpMethod, HttpRequest, HttpResponse } from "../http"; import { HttpHandler } from "../http4ts"; import { Key } from "./path-to-regexp"; export interface RoutedHttpRequest extends HttpRequest { routeParams: Record; } export declare type RoutedHttpHandler = (req: RoutedHttpRequest) => HttpResponse | Promise; export declare type UriTemplate = string; interface RouteDefinition { method?: HttpMethod; uriTemplate?: RegExp; keys?: Key[]; handler: RoutedHttpHandler; } /** * Creates an HttpHandler based of the defined routes. You can use this function to define the application router. * @param firstRouteDefinition Use one of the route definition creators like `get`, `post`, `notFound`, `all` and `route` * @param otherRouteDefinitions Use one of the route definition creators like `get`, `post`, `notFound`, `all` and `route`. This is the rest parameter; Can be added indefinitely. */ export declare function routes(firstRouteDefinition: RouteDefinition, ...otherRouteDefinitions: RouteDefinition[]): HttpHandler; /** * Defines a route for the provided request path and method * @param method HttpMethod for the route to be matched * @param path Uri template to define the path for this route handler * @param handler HttpHandler to be called when the request matches this route */ export declare function route(method: HttpMethod, path: UriTemplate, handler: RoutedHttpHandler): RouteDefinition; /** * Defines a route for the specified uri template no matter what http method used for the request * @param path Uri template to define the path for this route handler * @param handler HttpHandler to be called when the request matches this route */ export declare function all(path: UriTemplate, handler: RoutedHttpHandler): RouteDefinition; /** * Defines a route for a GET request * @param path Uri template to define the path for this route handler * @param handler HttpHandler to be called when the request matches this route */ export declare function get(path: UriTemplate, handler: RoutedHttpHandler): RouteDefinition; /** * Defines a route for a POST request * @param path Uri template to define the path for this route handler * @param handler HttpHandler to be called when the request matches this route */ export declare function post(path: UriTemplate, handler: RoutedHttpHandler): RouteDefinition; /** * Defines a fallback route when the request path does not match any routes * @param handler HttpHandler to be called when the request matches this route */ export declare function notFound(handler: RoutedHttpHandler): RouteDefinition; export {};