New Relay 3.2 adds request deduplication
The tiny HTTP client
The tiny HTTP client
that does the hard parts.
Relay is a 2.1 kB wrapper around fetch with timeouts, retries, interceptors and typed responses built in. It runs in browsers, Node.js, Deno, Bun and edge runtimes.
npm install @relayhttp/relaypnpm add @relayhttp/relayyarn add @relayhttp/relaybun add @relayhttp/relayDocumentation sections:
Quick startMake your first request in under five minutes.Installationnpm, pnpm, Yarn, Bun, Deno or a plain script tag.Core conceptsRequests, timeouts, retries, interceptors and errors.API referenceEvery function, option and type, with examples.ExamplesCopy-paste recipes for auth, uploads, polling and more.ChangelogWhat changed in each release, and how to upgrade.
#Why Relay?
The built-in fetch is great, but every project ends up writing the same helpers around it: a timeout, a retry loop, JSON parsing, error handling for non-2xx responses and a place to attach auth headers. Relay is those helpers, done carefully, in one small package with no dependencies.
2.1 kB
min + gzip, zero dependencies
100%
TypeScript, with typed responses
6
runtimes tested in CI
#A first look
Requests return a promise for the parsed body. Errors, including timeouts and non-2xx responses, reject with a RelayError you can inspect.
app.js
import relay from '@relayhttp/relay';
// GET and parse JSON in one step
const user = await relay.get('https://api.example.com/users/42').json();
// POST with a timeout and automatic retries
const order = await relay
.post('https://api.example.com/orders', {
json: { sku: 'MUG-01', quantity: 2 },
timeout: 5000,
retry: { limit: 3 },
})
.json();#Where to next
- New to Relay? Follow the quick start.
- Moving from Axios or plain
fetch? See the comparison in the FAQ. - Want to understand how retries and interceptors fit together? Read Core concepts.
Was this page helpful?
Last updated