Function matchRoute

Matches a request to one of the available routes.

  • Parameters

    • routes: Route[]

      An array of routes to match against.

    • request: Request

      The incoming HTTP request.

    Returns Route

    The matched route, or undefined if no match is found.

    Example usage:

    import { router, text, matchRoute } from "@pulsar-http/core";

    const routes = [
    router.get('/api/users', async () => text('User List')),
    ];

    // Faking the request for the example
    const route = matchRoute(routes, new Request('http://localhost:3000/api/users'));

    In this example route value is:

    {
    method: "GET",
    path: "/api/users",
    handler: [AsyncFunction: AsyncFunction],
    }