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.
134 lines (133 loc) • 4.01 kB
TypeScript
import { IncomingMessage, ServerResponse } from "http";
type Handler = (req: IncomingMessage, res: ServerResponse, params: Record<string, string>) => any;
export declare class FastRouter {
private trees;
private _routes;
constructor();
/**
* Get all registered routes in the router.
*
* Returns the internal route registry used for debugging,
* inspection, or serialization of the router tree.
*
* @returns Internal routes structure
*/
get routes(): {
path: string;
method: string;
params: string[];
}[];
/**
* Register a GET route.
*
* Handles HTTP GET requests for the specified path.
*
* @param path Route path (e.g. "/users/:id")
* @param handler Function executed when route matches
* @returns Router instance for chaining
*
* @example
* router.get("/users", (req, res) => {});
*/
get(path: string, handler: Handler): this;
/**
* Register a POST route.
*
* Used for creating resources or submitting data.
*
* @param path Route path
* @param handler Route handler function
* @returns Router instance for chaining
*/
post(path: string, handler: Handler): this;
/**
* Register a PUT route.
*
* Typically used for full resource replacement.
*
* @param path Route path
* @param handler Route handler function
* @returns Router instance for chaining
*/
put(path: string, handler: Handler): this;
/**
* Register a PATCH route.
*
* Used for partial updates to a resource.
*
* @param path Route path
* @param handler Route handler function
* @returns Router instance for chaining
*/
patch(path: string, handler: Handler): this;
/**
* Register a DELETE route.
*
* Used for removing a resource.
*
* @param path Route path
* @param handler Route handler function
* @returns Router instance for chaining
*/
delete(path: string, handler: Handler): this;
/**
* Register an OPTIONS route.
*
* Used for CORS preflight requests or capability discovery.
*
* @param path Route path
* @param handler Route handler function
* @returns Router instance for chaining
*/
options(path: string, handler: Handler): this;
/**
* Register a HEAD route.
*
* Same as GET but returns headers only (no body).
*
* @param path Route path
* @param handler Route handler function
* @returns Router instance for chaining
*/
head(path: string, handler: Handler): this;
/**
* Register a route for all HTTP methods.
*
* This registers the same handler for every supported HTTP method.
* Useful for middleware-like or catch-all behavior.
*
* @param path Route path
* @param handler Route handler function
* @returns Router instance for chaining
*
* @example
* router.all("/health", (req, res) => res.send("OK"));
*/
all(path: string, handler: Handler): this;
/**
* Lookup a route handler based on the incoming request.
*
* This method is responsible for resolving the correct route
* from the registered router tree and executing the matched handler.
*
* It supports parameterized routes, static routes, and (optionally)
* wildcard matching depending on router implementation.
*
* @param {IncomingMessage} req Incoming HTTP request object
* @param {ServerResponse} res Server response object used to send output
*
* @returns void
*
* @example
* router.lookup(req, res);
*
* @internal
* This is typically called by the HTTP server layer and should not
* be invoked directly in most application code.
*/
lookup(req: IncomingMessage, res: ServerResponse): any;
private _createNode;
private _add;
private _extractParams;
}
export {};