Installation
Relay ships as an ES module with TypeScript types included. It works anywhere the standard fetch API exists.
#Package managers
Pick your package manager. Your choice is remembered across every page of these docs.
npm install @relayhttp/relaypnpm add @relayhttp/relayyarn add @relayhttp/relaybun add @relayhttp/relay#Requirements
| Runtime | Minimum version | Notes |
|---|---|---|
| Node.js | 18.0 | Uses the built-in fetch. No polyfill needed. |
| Deno | 1.35 | Import from npm:@relayhttp/relay. |
| Bun | 1.0 | Works out of the box. |
| Browsers | Last 2 versions | Chrome, Edge, Firefox and Safari 15.4+. |
| Edge runtimes | – | Cloudflare Workers, Vercel Edge and Netlify Edge. |
#Without a bundler
Load the module build straight from a CDN with a module script. This is handy for prototypes and plain HTML pages.
index.html
<script type="module">
import relay from 'https://cdn.example.com/@relayhttp/relay@3.2.0/dist/relay.min.js';
const status = await relay.get('/api/status').json();
document.querySelector('#status').textContent = status.message;
</script>#TypeScript
Types are bundled, so there's nothing extra to install. Pass a type parameter to .json() to type the response body:
user.ts
interface User {
id: number;
name: string;
email: string;
}
const user = await relay.get('users/42').json<User>();
user.email; // string#Deno
main.ts
import relay from 'npm:@relayhttp/relay@3';
const { version } = await relay.get('https://api.example.com/version').json();#Verify the install
Run this one-liner to check that Relay loads and can reach the network:
Terminal
node -e "import('@relayhttp/relay').then(m => m.default.get('https://httpbin.org/get').json()).then(r => console.log('ok', r.url))"Was this page helpful?
Last updated