tspace-spear
Version:
tspace-spear is a lightweight API framework for Node.js that is fast and highly focused on providing the best developer experience. It utilizes the native HTTP server
80 lines (79 loc) • 3.52 kB
TypeScript
import type { TContext, TMethods, TNextFunction } from "../types";
declare class Router {
private _routes;
get routes(): {
path: string;
method: TMethods;
handlers: ((ctx: TContext, next: TNextFunction) => 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 {void}
*/
groups(prefix: `/${string}`, router: (router: Router) => Router): void;
/**
* 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: TContext, next: TNextFunction) => 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: TContext, next: TNextFunction) => 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: TContext, next: TNextFunction) => 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: TContext, next: TNextFunction) => 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: TContext, next: TNextFunction) => 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: TContext, next: TNextFunction) => any)[]): this;
}
export { Router };
export default Router;