Relay
New Relay 3.2 adds request deduplication

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/relay

Documentation sections:

#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

Was this page helpful?

Edit this page on GitHub

Last updated