http-micro
Version:
Micro-framework on top of node's http module
26 lines (25 loc) • 1.87 kB
TypeScript
/// <reference types="raw-body" />
/// <reference types="node" />
import * as http from "http";
import * as rawBody from "raw-body";
import * as qs from "querystring";
export declare type ParserCallback = (error: rawBody.RawBodyError, body?: string | Buffer) => void;
export declare type Parser = (req: http.IncomingMessage, callback: ParserCallback, opts?: any) => void;
export declare function rawBodyParserFactory(): (req: http.IncomingMessage, callback: ParserCallback, opts?: any) => void;
export declare type JsonBodyParserOpts = rawBody.Options & {
reviver?: (key: any, value: any) => any;
};
export declare function jsonBodyParserFactory(opts: JsonBodyParserOpts, baseParser?: Parser): (req: http.IncomingMessage, callback: ParserCallback, baseParserOpts?: any) => void;
export declare type FormBodyParserOpts = rawBody.Options & {
parser?: (str: string, sep?: string, eq?: string, options?: qs.ParseOptions) => any;
sep?: string;
eq?: string;
options?: qs.ParseOptions;
};
export declare function formBodyParserFactory(opts: FormBodyParserOpts, baseParser?: Parser): (req: http.IncomingMessage, callback: ParserCallback, baseParserOpts?: any) => void;
export declare type AnyParserOptions = FormBodyParserOpts & JsonBodyParserOpts;
export declare function anyBodyParserFactory(opts?: AnyParserOptions, baseParser?: Parser): (req: http.IncomingMessage, callback: ParserCallback, baseParserOpts?: any) => void;
export declare function createAsyncParser(parser: Parser): (req: http.IncomingMessage, opts?: any) => Promise<any>;
export declare function parseBody<T>(req: http.IncomingMessage, opts?: any, parser?: Parser): Promise<T>;
export declare function handleRequestBodyAbsence(req: http.IncomingMessage, callback: ParserCallback): boolean;
export declare function hasBody(req: http.IncomingMessage): boolean;