micro-handlers
Version:
Different handlers based on HTTP method for Micro
14 lines (9 loc) • 448 B
TypeScript
import { IncomingMessage, ServerResponse } from 'http'
declare type Function = (...args: any[]) => any
export declare type DefaultHandler = (req: IncomingMessage, res: ServerResponse) => any
export declare type Method = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'
export declare type Handlers<T> = {
[K in Method]?: T
}
declare function microHandlers<T extends Function = DefaultHandler>(handlers: Handlers<T>): T
export default microHandlers