Skip to content

Taxum / @taxum/core / routing / extractHandler

Variable: extractHandler

const extractHandler: ExtractHandler

Defined in: routing/handler.ts:84

Creates a request handler that processes an HTTP request using the provided extractors and function.

This allows you to separate request data parsing (via extractors) from business logic (the handler), making route definitions cleaner and more type-safe.

You can either pass in each extractor individually as positional arguments or all extractors as a single array as the first argument.

Behavior

  • All extractors are executed in parallel via Promise.all().
  • If an extractor throws, the error is propagated to the router’s error handler.
  • The order of extractor definitions determines the order of arguments passed to the handler.

Examples

ts
import { extractHandler } from "@taxum/core/routing";
import { pathParam, json } from "@taxum/core/extract";
import { z } from "zod";

const handler = extractHandler(
    pathParam(z.uuid()),
    json(z.object({ name: z.string() }})),
    (id, body) => {
        // do something with `id` and `body`
    },
);
ts
import { extractHandler } from "@taxum/core/routing";
import { pathParam, json } from "@taxum/core/extract";
import { z } from "zod";

const handler = extractHandler(
    [
        pathParam(z.uuid()),
        json(z.object({ name: z.string() }})),
    ],
    (id, body) => {
        // do something with `id` and `body`
    },
);