Registry / testing / hydra-fetch

hydra-fetch

JSON →
library0.2.0jsnpmunverified

A lightweight, isomorphic Hydra client built on the Fetch API for consuming Hydra-powered hypermedia APIs. Current stable version 0.2.0 is in early development with monthly releases. It differentiates by being promise-based, supporting both Node.js and browser environments, and offering a simple interface to retrieve resources, follow links, and execute operations defined by Hydra vocabularies. It is designed for developers building clients for Hydra-enabled APIs without heavy dependencies.

npm install hydra-fetch
INSTALL
IMPORT
SIG · HYDRA-FETCH
H
hydra-fetch
testingjavascriptv0.2.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import Hydra from 'hydra-fetch'
const Hydra = require('hydra-fetch')
Package is ESM-only; CommonJS require not supported.
Hydra
import { Hydra } from 'hydra-fetch'
import { Hydra } from 'hydra-fetch/lib/index.js'
Named export 'Hydra' is available from the main entry.
type HydraResource
import type { HydraResource } from 'hydra-fetch'
import { HydraResource } from 'hydra-fetch'
For TypeScript, use type-only import to avoid runtime overhead.

Shows how to create a Hydra client, load an entry point, fetch a resource, and invoke operations using hydra-fetch.

import Hydra from 'hydra-fetch'; const hydra = new Hydra({ baseUrl: 'http://example.com/api', fetch: fetch.bind(globalThis) }); (async () => { const entryPoint = await hydra.load('/entry'); console.log('Entry point loaded:', entryPoint.id); const resource = await hydra.fetchResource('http://example.com/api/resource/1'); console.log('Resource properties:', resource.properties); for await (const operation of resource.operations) { if (operation.method === 'GET') { const result = await hydra.invokeOperation(operation); console.log('Operation result:', result); } } })().catch(err => console.error(err));
Debug
Known issues
breakinghydra-fetch v0.2.0 changes the constructor signature; 'baseUrl' is now mandatory.
fix
Update Hydra constructor call to include { baseUrl: 'your-base-url' }.
affects: <0.2.0
gotchaThe fetch polyfill must be provided in Node.js versions <18; otherwise hydra-fetch uses global fetch which may be undefined.
fix
In Node.js <18, provide a fetch polyfill (e.g., cross-fetch) via the constructor option.
affects: *
deprecatedThe method `hydra.fetchResource()` is deprecated in favor of `hydra.load()` since v0.2.0.
fix
Replace `hydra.fetchResource(url)` with `hydra.load(url)`.
affects: >=0.2.0
Errors
Common errors & fixes
TypeError: Failed to parse URL from ...
Relative URLs resolved incorrectly when no base URL set.
fix
Ensure baseUrl is set in the Hydra constructor and use absolute URLs or paths relative to baseUrl.
Error: fetch is not defined
Using hydra-fetch in Node.js without polyfill or native fetch.
fix
Provide a fetch polyfill, e.g., install cross-fetch and pass { fetch: require('cross-fetch') } (or use global fetch in Node 18+).
Upgrade
Version history
0.2.0latest on npm
Audit
Dependencies
hydrarequiredCore Hydra vocabulary and hypermedia support
cross-fetchoptionalPolyfill for fetch in Node.js when native fetch unavailable
Agent activity
11 hits · last 30 days
node
10
Resources
hydra-fetch — npm install hydra-fetch · libregistry