Release candidate — 1.0.0-rc.6
StitchAPI
GuidesAuthoring & composition

.with() partial application

Pre-bind part of a call and reuse the same runtime so cookies, throttle, and sessions persist.

Use .with() when you want to pre-bind part of a stitch's input — a query param, a header, a body field — and reuse it across calls, while the bound stitch keeps the same runtime so cookies, throttle counters, and session state carry over.

Example

import {  } from 'stitchapi';

const  = ('https://api.example.com/search');

// Pre-bind a query param; per-call input merges over it.
const  = .({ : { : 'eu' } });

await ({ : { : 'mango' } }); // → region=eu&q=mango

inEurope shares one runtime with search, so a throttle budget or a captured cookie set is the same whichever you call.

Options

.with(partial) accepts any slice of StitchInputparams, query, headers, body, or variables — and returns a new stitch with that slice bound in.

Each call merges its own input over the bound partial, so per-call values win on conflict (region here, overridden if a call passes its own region). Calls are chainable: search.with(a).with(b) layers both partials.

The key point is the shared runtime: the bound stitch does not start fresh. The same cookie session jar, throttle counters, and shared session state persist across every call made through it.

Anti-pattern: don't reach for .with() to get an isolated copy with its own throttle budget or circuit-breaker state — because the runtime is shared, a bound stitch draws from the same buckets and the same breaker counter as its parent. When you need separate state, declare a separate stitch instead of binding one. See throttle.

See also

On this page