npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@axonsdev/hateoas-fetch

v0.1.0

Published

Fetch-based transport for `@axonsdev/hateoas-core`.

Readme

@axonsdev/hateoas-fetch

Fetch-based transport for @axonsdev/hateoas-core.

This package adapts the platform fetch API to the HypermediaTransport contract. It is usable in browsers, Node runtimes that provide fetch, and tests that inject a custom fetchFn.

Responsibilities

  • Resolve relative URLs against an optional baseUrl.
  • Add dynamic headers before each request.
  • Pass credentials to fetch.
  • Serialize request bodies as JSON.
  • Normalize response headers, content type, status, and body.
  • Throw HypermediaHttpError for non-2xx responses.

Main Exports

fetchTransport(options)
FetchHypermediaTransport
FetchHypermediaTransportOptions

Basic Usage

import { createHateoasClient } from '@axonsdev/hateoas-core';
import { fetchTransport } from '@axonsdev/hateoas-fetch';
import { sirenParser } from '@axonsdev/hateoas-siren';

const client = createHateoasClient({
  transport: fetchTransport({
    baseUrl: 'http://localhost:3000',
  }),
  parsers: [sirenParser()],
});

Options

interface FetchHypermediaTransportOptions {
  baseUrl?: string;
  credentials?: RequestCredentials;
  headers?: () => Record<string, string> | Promise<Record<string, string>>;
  fetchFn?: typeof fetch;
}

baseUrl

Used to resolve relative hrefs.

fetchTransport({
  baseUrl: 'https://api.example.com',
});

A request to /api/cases becomes https://api.example.com/api/cases.

credentials

Passed through to fetch.

fetchTransport({
  credentials: 'include',
});

headers

Called before every request. This is useful for auth tokens, tenant IDs, or demo role headers.

fetchTransport({
  headers: () => ({
    Authorization: `Bearer ${tokenStore.current()}`,
  }),
});

The transport merges dynamic headers with request-specific headers from the HATEOAS client. Request-specific headers win when keys overlap.

fetchFn

Inject a custom fetch implementation.

fetchTransport({
  fetchFn: testFetch,
});

This is useful in tests or runtimes where globalThis.fetch is not available.

Response Handling

The transport reads the body as JSON when the content type includes json.

Otherwise, it reads the body as text.

204 No Content returns undefined as the body.

Error Handling

Non-OK responses throw:

new HypermediaHttpError(response.status, body)

The parsed body is attached to the error so application code can inspect API error details.

Implementation Note

The default fetch is bound with fetch.bind(globalThis). Browser fetch can throw Illegal invocation when called after being detached from window; binding avoids that runtime failure.