Taxum / @taxum/core / extract / pathParam
Function: pathParam()
pathParam<
T
>(schema
):Extractor
<InferOutput
<T
>>
Defined in: extract/path.ts:43
Extractor that will get a single path param from the URL and parse it.
The schema can be anything implementing the Standard Schema.
If your path contains more than one value, you must use pathParams instead.
If the param 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 { pathParam } from "@taxum/core/extract";
import { m, Router } from "@taxum/core/routing";
import { z } from "zod";
const handler = handler([pathParam(z.uuid())], ({id}) => {
// ...
});
const router = new Router()
.route("/users/:id", m.get(handler));
Throws
Error if path params have more than one value.
Throws
InvalidPathParamsError if the params cannot be parsed.