Catch a breaking API change before your users do
Wrap output with drift to compare every response against a committed snapshot and flag dropped fields, type flips, and new keys by severity.
Task
A vendor can rename or drop a field without telling you, and a plain type check will not notice until something breaks in production. You want to be warned the moment the response shape moves — and to triage it by severity, not panic on every change.
Example
One way: wrap the output schema with drift and a committed baseline.
import { , } from 'stitchapi';
import { } from 'zod';
const = ({
: 'https://api.example.com',
: '/users/{id}',
: (.({ : .(), : .() }), {
: ['id'],
: ['email'],
: 'users.contract.json',
}),
});
const = await ({ : { : 1 } });How it works
The first call records the baseline into users.contract.json (check it into
the repo); every call after compares the response and emits leveled findings.
critical paths change at level error — that breaks the contract and throws
STITCH_DRIFT. watch paths change at warn, and
brand-new fields default to info (onNew). warn and info findings do
not throw — they ride the event stream as
drift events, so you can watch a field erode
before it breaks. This is the opposite end from plain
validation, which rejects one malformed
response hard, here and now.
See also
Retry a write without double-charging
Attach an idempotency key so a retried POST settles once, not twice.
Catch a silent selector rename in scraped HTML
Scrape an HTML page into a structured object with transform, then drift the structured shape so a markup or selector rename becomes a loud contract error instead of a silently missing field.