UNPKG

@gati-framework/runtime

Version:

Gati runtime execution engine for running handler-based applications

105 lines 2.66 kB
/** * @module runtime/route-manager * @description Route registration and matching */ import type { Route, RouteMatch, RouterConfig } from './types/route.js'; import type { Handler } from './types/handler.js'; import type { HttpMethod } from './types/request.js'; /** * Route manager for registering and matching routes */ export declare class RouteManager { private routes; constructor(_config?: RouterConfig); /** * Register a new route * * @param method - HTTP method * @param path - Route path pattern * @param handler - Handler function * * @example * ```typescript * routeManager.register('GET', '/users/:id', getUserHandler); * ``` */ register(method: HttpMethod, path: string, handler: Handler): void; /** * Register a GET route */ get(path: string, handler: Handler): void; /** * Register a POST route */ post(path: string, handler: Handler): void; /** * Register a PUT route */ put(path: string, handler: Handler): void; /** * Register a PATCH route */ patch(path: string, handler: Handler): void; /** * Register a DELETE route */ delete(path: string, handler: Handler): void; /** * Register a HEAD route */ head(path: string, handler: Handler): void; /** * Register an OPTIONS route */ options(path: string, handler: Handler): void; /** * Find a matching route for the given method and path * * @param method - HTTP method * @param path - Request path * @returns RouteMatch if found, null otherwise * * @example * ```typescript * const match = routeManager.match('GET', '/users/123'); * if (match) { * console.log(match.params.id); // '123' * } * ``` */ match(method: HttpMethod, path: string): RouteMatch | null; /** * Get all registered routes */ getRoutes(): Route[]; /** * Unregister a route */ unregister(method: HttpMethod, path: string): void; /** * Clear all registered routes */ clear(): void; /** * Get the number of registered routes */ size(): number; } /** * Create a new route manager instance * * @param config - Router configuration * @returns New RouteManager instance * * @example * ```typescript * const router = createRouteManager({ * strict: true, * caseSensitive: false * }); * * router.get('/users/:id', getUserHandler); * ``` */ export declare function createRouteManager(config?: RouterConfig): RouteManager; //# sourceMappingURL=route-manager.d.ts.map