Registry / devops / ldfetch

ldfetch

JSON →
library1.2.8jsnpmunverified

An HTTP client for fetching Linked Data RDF resources in Node.js and the browser. Current stable version is 1.2.8. It enhances standard fetch by setting appropriate Accept headers for RDF serializations, uses rdf-parse to support multiple RDF formats, returns triples/quads in RDFJS representation, and emits events for request lifecycle. It automatically follows redirects, supports HTTP caching, and can limit concurrent requests. The CLI tool can output TriG or use JSON-LD framing. Key differentiators: single library for both Node.js and browser, event-driven, and built on top of rdf-parse for broad format support.

npm install ldfetch
INSTALL
IMPORT
SIG · LDFETCH
L
ldfetch
devopsjavascriptv1.2.8
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 ldfetch from 'ldfetch'
const ldfetch = require('ldfetch')
Package exports a default class. ESM import is preferred.
default (CommonJS)
const ldfetch = require('ldfetch')
const { ldfetch } = require('ldfetch')
CommonJS require returns the constructor directly.
default (browser)
const fetcher = new window.ldfetch()
import { ldfetch } from 'ldfetch'
In browser, use the global 'window.ldfetch' from the dist file.

Shows how to import ldfetch, fetch a URL, access triples, and use JSON-LD framing.

import ldfetch from 'ldfetch'; const fetch = new ldfetch(); async function main() { const response = await fetch.get('https://ruben.verborgh.org/'); console.log('Response URL:', response.url); console.log('Triples count:', response.triples.length); // Use JSON-LD framing const framed = await fetch.frame(response.triples, {'@graph': {}}); console.log('Framed result:', framed); } main().catch(console.error);
Debug
Known issues
breakingConstructor expects an options object, not a URL string.
fix
Use: new ldfetch({}) instead of new ldfetch(url)
affects: all
gotchaThe get() method returns a promise that resolves to an object with triples, url, and responseCode, not the raw response.
fix
Access triples via response.triples, not response.data
affects: all
gotchaIn browser, you must include the dist file and use window.ldfetch, not import.
fix
Use <script src="dist/main.js"></script> and new window.ldfetch()
affects: all
deprecatedUsing require('ldfetch') is deprecated; prefer ESM imports.
fix
Use import ldfetch from 'ldfetch'
affects: >=1.0
gotchaThe frame() method expects triples (array) and a frame object, not just a URL.
fix
Call fetch.frame(response.triples, frameObject)
affects: all
Errors
Common errors & fixes
TypeError: ldfetch is not a constructor
Using ES module import incorrectly or missing default import
fix
Use: import ldfetch from 'ldfetch' (not { ldfetch })
ReferenceError: ldfetch is not defined
In browser, forgetting to include the dist script
fix
Add <script src="dist/main.js"></script> before using window.ldfetch
Cannot find module 'ldfetch'
Package not installed, or wrong path
fix
Run: npm install ldfetch
TypeError: response.triples is undefined
Assuming response is a typical fetch Response object
fix
Access response.triples, but ensure the promise resolved correctly; check network.
Upgrade
Version history
1.2.8latest on npm
Audit
Dependencies
rdf-parserequiredUsed to parse RDF serializations into triples/quads
cross-fetchrequiredProvides fetch API for Node.js and browser compatibility
Agent activity
8 hits · last 30 days
node
8
Resources
ldfetch — npm install ldfetch · libregistry