@ne1410s/xprest
Version:
RESTful express core library
50 lines (49 loc) • 2 kB
TypeScript
import { Mdw, PassiveMdw } from './middleware';
export declare class Xprest {
private readonly api;
constructor();
/**
* Applies global middleware. Example uses include providing default headers,
* logging, etc.
* @param handlers
*/
global(...handlers: PassiveMdw<any>[]): void;
/**
* Specifies a static file resource.
* @param apiRoute The api route.
* @param localPath The file path, relative to the cwd.
*/
resource<TReq>(apiRoute: string, localPath: string, mdwPre?: PassiveMdw<TReq>[], mdwPost?: PassiveMdw<TReq>[]): void;
/**
* Specifies a dynamic file resource.
* @param apiRoute The api route.
* @param localPath The file path, relative to the cwd.
* @param variables Exposed in the rendering of the file. For example:
* <%= new Date().getTime() * myVar.myProp %>
*/
render<TReq>(apiRoute: string, localPath: string, variables: object, mdwPre?: PassiveMdw<TReq>[], mdwPost?: PassiveMdw<TReq>[]): void;
/**
* Specifies a streamable resource; e.g. video.
* @param apiRoute The api route.
* @param localPath The file path, relative to the cwd.
* @param mime The mime type.
*/
stream<TReq>(apiRoute: string, localPath: string, mime: string, mdwPre?: PassiveMdw<TReq>[]): void;
/**
* Specifies a restful api endpoint.
* @param apiRoute The api route.
* @param verb The verb.
* @param handler Handles requests.
*/
endpoint<TReq, TRes>(apiRoute: string, verb: 'post' | 'get' | 'patch' | 'delete' | 'put', ...handlers: Mdw<TReq, TRes>[]): void;
/**
* Starts listening for the specified requests.
* @param port The port.
* @param onready Called once listening is in place.
*/
start(port: number, onready?: () => void): void;
/** Provides express pipeline handler for media streaming. */
private xp_Stream;
/** Converts middleware functions to express-style handlers. */
private convert;
}