hyperfetch

v0.2.2
Fetch JSON-LD from any URI if possible
json-ld rdf linked data solid

Hyperfetch

Hyperfetch tries to fetch JSON-LD from any URI.

Quickstart

import hyperfetch from 'hyperfetch'

hyperfetch('https://api.example/resource').then(jsonld => {
  console.log(jsonld)
});

Supported Content-Types

A resource representation may be delivered as one of the following Content-Types:

  • application/ld+json
  • application/rdf+xml
  • application/trig
  • application/n-quads
  • application/n-triples
  • text/n3
  • text/turtle

For any supported Content-Type, hyperfetch will return a JSON-LD object!

Unsupported Content-Types cause an error.

Passing custom options

You may pass an options object as second argument, to set for example HTTP headers or use a specific implementation of fetch.

hyperfetch('https://api.example/resource', {
  // custom options
})

For details see documentation of the underlying library @rdfjs/fetch-lite

Storing data to hyperfact

The data retrieved by hyperfetch can directly be merged to a hyperfact store:


import hyperfetch from 'hyperfetch';
import createStore from 'hyperfact';

export const facts = createStore();

hyperfetch("https://api.example/resource")
  .then(resource => facts.merge(resource))
npm i hyperfetch

Metadata

  • MIT
  • Whatever
  • Angelo Veltens
  • released 5/28/2019

Downloads

Maintainers