Skip to content

Taxum / @taxum/core / extract / pathParams

Function: pathParams()

pathParams<T>(schema): Extractor<InferOutput<T>>

Defined in: extract/path.ts:97

Extractor that will get path params from the URL and parse them.

The schema can be anything implementing the Standard Schema.

If the params cannot be parsed, it will reject the request with a 400 Bad Request response.

Type Parameters

T

T extends StandardSchemaV1<unknown, unknown>

Parameters

schema

T

Returns

Extractor<InferOutput<T>>

Example

ts
import { pathParams } from "@taxum/core/extract";
import { m, Router } from "@taxum/core/routing";
import { z } from "zod";

const pathParamsSchema = z.object({
    foo: z.string(),
});

const handler = handler([pathParams(pathParamsSchema)], ({foo}) => {
    // ...
});

const router = new Router()
    .route("/users/:foo", m.post(handler));

Throws

InvalidPathParamsError if the params cannot be parsed.