/// /// import type * as stream from "stream"; import type * as fetch from "node-fetch"; import type { IMiddlewareAdapterHandler } from "./base-component"; import type { ParseUrlParams as _ParseUrlParams } from "typed-url-params"; /** * @alpha */ export declare namespace IHttpServerComponent { type JsonBody = Record; type ResponseBody = JsonBody | stream.Readable | Uint8Array | Buffer | string; type QueryParams = Record; type UrlParams = Record; type IRequest = fetch.Request; type IResponse = fetch.ResponseInit & { body?: ResponseBody; }; type DefaultContext = Context & { request: IRequest; url: URL; }; type PathAwareContext = Context & { params: string extends Path ? any : IHttpServerComponent.ParseUrlParams; }; type IRequestHandler = IMiddlewareAdapterHandler, IResponse>; type ParseUrlParams = {}> = _ParseUrlParams; /** * HTTP request methods. * * HTTP defines a set of request methods to indicate the desired action to be * performed for a given resource. Although they can also be nouns, these * request methods are sometimes referred as HTTP verbs. Each of them implements * a different semantic, but some common features are shared by a group of them: * e.g. a request method can be safe, idempotent, or cacheable. * * @public */ type HTTPMethod = /** * The `CONNECT` method establishes a tunnel to the server identified by the * target resource. */ "CONNECT" /** * The `DELETE` method deletes the specified resource. */ | "DELETE" /** * The `GET` method requests a representation of the specified resource. * Requests using GET should only retrieve data. */ | "GET" /** * The `HEAD` method asks for a response identical to that of a GET request, * but without the response body. */ | "HEAD" /** * The `OPTIONS` method is used to describe the communication options for the * target resource. */ | "OPTIONS" /** * The PATCH method is used to apply partial modifications to a resource. */ | "PATCH" /** * The `POST` method is used to submit an entity to the specified resource, * often causing a change in state or side effects on the server. */ | "POST" /** * The `PUT` method replaces all current representations of the target * resource with the request payload. */ | "PUT" /** * The `TRACE` method performs a message loop-back test along the path to the * target resource. */ | "TRACE"; interface PathAwareHandler { ( /** * /path/to/:bind */ path: Path, /** * adapter code to handle the request */ handler: IHttpServerComponent.IRequestHandler>): void; } type MethodHandlers = { [key in Lowercase]: PathAwareHandler; }; } /** * @alpha */ export interface IHttpServerComponent { /** * Register a route */ use: ( /** * adapter code to handle the request */ handler: IHttpServerComponent.IRequestHandler) => void; /** * Sets a context to be passed on to the handlers. * * The original context should remain untouched after handler execution. */ setContext(ctx: Context): void; } //# sourceMappingURL=http-server.d.ts.map