UNPKG

tspace-spear

Version:

tspace-spear is a lightweight, high-performance API framework for Node.js that leverages the native HTTP server and supports uWebSockets.js (C++) for maximum speed and efficiency.

100 lines (99 loc) 4.48 kB
import type { T } from "../types"; declare class Router { private _routes; get routes(): { path: string; method: T.Method; handlers: ((ctx: T.Context, next: T.NextFunction) => any)[]; }[]; /** * The 'groups' method is used to add the request handler to the router for 'GET' 'POST' 'PUT' 'PATCH' 'DELETE' methods. * * @param {string} prefix * @param {Router} router * @returns {this} */ groups(prefix: `/${string}`, router: (router: Router) => Router): this; /** * The 'get' method is used to add the request handler to the router for the 'GET' method. * * @param {string} path * @callback {...Function[]} handlers of the middlewares * @property {Object} ctx - context { req , res , query , params , cookies , files , body} * @property {Function} next - go to next function * @returns {this} */ get(path: `/${string}`, ...handlers: ((ctx: T.Context, next: T.NextFunction) => any)[]): this; /** * The 'post' method is used to add the request handler to the router for the 'POST' method. * * @param {string} path * @callback {...Function[]} handlers of the middlewares * @property {Object} ctx - context { req , res , query , params , cookies , files , body} * @property {Function} next - go to next function * @returns {this} */ post(path: `/${string}`, ...handlers: ((ctx: T.Context, next: T.NextFunction) => any)[]): this; /** * The 'put' method is used to add the request handler to the router for the 'PUT' method. * * @param {string} path * @callback {...Function[]} handlers of the middlewares * @property {Object} ctx - context { req , res , query , params , cookies , files , body} * @property {Function} next - go to next function * @returns {this} */ put(path: `/${string}`, ...handlers: ((ctx: T.Context, next: T.NextFunction) => any)[]): this; /** * The 'patch' method is used to add the request handler to the router for the 'PATCH' method. * * @param {string} path * @callback {...Function[]} handlers of the middlewares * @property {Object} ctx - context { req , res , query , params , cookies , files , body} * @property {Function} next - go to next function * @returns {this} */ patch(path: `/${string}`, ...handlers: ((ctx: T.Context, next: T.NextFunction) => any)[]): this; /** * The 'delete' method is used to add the request handler to the router for the 'DELETE' method. * * @param {string} path * @callback {...Function[]} handlers of the middlewares * @property {Object} ctx - context { req , res , query , params , cookies , files , body} * @property {Function} next - go to next function * @returns {this} */ delete(path: `/${string}`, ...handlers: ((ctx: T.Context, next: T.NextFunction) => any)[]): this; /** * The 'all' method is used to add the request handler to the router for 'GET' 'POST' 'PUT' 'PATCH' 'DELETE' methods. * * @param {string} path * @callback {...Function[]} handlers of the middlewares * @property {object} ctx - context { req , res , query , params , cookies , files , body} * @property {function} next - go to next function * @returns {this} */ all(path: `/${string}`, ...handlers: ((ctx: T.Context, next: T.NextFunction) => any)[]): this; /** * The 'head' method is used to add the request handler to the router for the 'HEAD' method. * * @param {string} path * @callback {...Function[]} handlers of the middlewares * @property {Object} ctx - context { req , res , query , params , cookies , files , body} * @property {Function} next - go to next function * @returns {this} */ head(path: `/${string}`, ...handlers: ((ctx: T.Context, next: T.NextFunction) => any)[]): this; /** * The 'options' method is used to add the request handler to the router for the 'OPTIONS' method. * * @param {string} path * @callback {...Function[]} handlers of the middlewares * @property {Object} ctx - context { req , res , query , params , cookies , files , body} * @property {Function} next - go to next function * @returns {this} */ options(path: `/${string}`, ...handlers: ((ctx: T.Context, next: T.NextFunction) => any)[]): this; } export { Router }; export default Router;