Under heavy development
StitchAPI
GuidesData shaping

transform

Reshape a response before unwrap and validation — for example, scrape HTML into structured data.

Use transform when the raw response isn't yet the shape the rest of the pipeline expects — scrape HTML text into a structured object, or flatten an odd envelope — so a single function reshapes the body before unwrap and validation ever see it.

Example

import {  } from 'stitchapi';

const  = ({
    : 'https://api.example.com',
    : '/listings',
    // The body is `unknown` — narrow it, then reshape the raw envelope into a
    // plain array before unwrap and validation run.
    : () => ( as { : unknown[] }).,
});

The raw body arrives as a wrapped { results: [...] }; transform returns the inner array, and everything downstream works against that array instead.

Options

transform?: (body: unknown) => unknown runs first in the response pipeline — before unwrap and before validation (and drift). That ordering is the point: reshape a raw body — scrape HTML text into a structured object, or flatten an odd envelope — into the shape unwrap and validation are written for, rather than bending them around the source's quirks.

body is typed unknown, so narrow it before reading (a cast or a type guard) and return any reshaped value. See Reference → Config types for every field.

transform runs before validation, so its output is unchecked — a wrong narrowing surfaces later as drift, not here.

See also

On this page