Function getPathParams

Extracts parameters from the request URL based on the route path.

  • Parameters

    • request: Request

      The incoming HTTP request.

    • routePath: string

      The path template of the matched route.

    Returns {}

    An object containing the extracted parameters.

    Example usage:

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

    const myRoute = router.get('/api/users/:id', async () => text('User List'));

    // Fake the request for the example
    const request = new Request('http://localhost:3000/api/users/123');
    const params = getPathParams(request, myRoute.path);

    In this example, params will be:

    {
    id: "123",
    }