Skip to content

Taxum / @taxum/core / extract / query

Function: query()

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

Defined in: extract/query.ts:44

Extractor that parses the query through a schema.

The schema can be anything implementing the Standard Schema.

If the query 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 { query } from "@taxum/core/extract";
import { m, Router } from "@taxum/core/routing";
import { z } from "zod";

const paginationSchema = z.object({
    page: z.coerce.number().int().nonnegative(),
});

const handler = handler([query(paginationSchema)], (pagination) => {
    const page = pagination.page;

    // ...
});

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

Throws

InvalidQueryDataError if the query cannot be parsed.