Function validateParams

  • Validate the path parameters in a request with a Zod schema. Throws an exception if the query parameters do not match the schema. You can use ExceptionWrapper to automatically catch the exception and send it to the client.

    Type Parameters

    • T extends ZodType<any, ZodTypeDef, any>

    Parameters

    Returns Promise<z.infer<T>>

    The validated path parameters

    import { validateParams } from 'next-api-utils';
    import { z } from 'zod';

    export const GET = (request, segmentData) => {
    const params = validateParams(segmentData, z.object({ foo: z.string() }));
    };

    InvalidPathParametersException Thrown if the path parameters failed validation