# rdf-dereference

> Dereferences a URL for its RDF contents

Latest version **5.0.0** (published 2026-01-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install rdf-dereference
pnpm add rdf-dereference
yarn add rdf-dereference
bun add rdf-dereference
```

Provides the command `rdf-dereference`.

## Health

**Score 60/100 (C)** — status: stable.

Positive: has types; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 5.0.0 |
| Published | 2026-01-09 |
| First published | 2019-09-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 32 |
| Unpacked size | 83.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 39 |
| Author | Ruben Taelman |
| Maintainers | rubensworks |
| Keywords | rdf, dereference, fetch, parse, stream, rdfjs, linked data |

## Links

- npm: https://www.npmjs.com/package/rdf-dereference
- Repository: https://github.com/rubensworks/rdf-dereference.js
- Homepage: https://github.com/rubensworks/rdf-dereference.js#readme
- Issues: https://github.com/rubensworks/rdf-dereference.js/issues
- Funding: https://github.com/sponsors/rubensworks/
- npm.io page: https://npm.io/package/rdf-dereference

## Dependencies (32)

- [rdf-string](https://npm.io/package/rdf-string.md) ^2.0.1
- [@rdfjs/types](https://npm.io/package/@rdfjs/types.md) *
- [@comunica/core](https://npm.io/package/@comunica/core.md) ^5.0.0
- [rdf-data-factory](https://npm.io/package/rdf-data-factory.md) ^2.0.2
- [stream-to-string](https://npm.io/package/stream-to-string.md) ^1.2.1
- [@comunica/bus-http](https://npm.io/package/@comunica/bus-http.md) ^5.0.0
- [@comunica/bus-init](https://npm.io/package/@comunica/bus-init.md) ^5.0.0
- [@comunica/bus-rdf-parse](https://npm.io/package/@comunica/bus-rdf-parse.md) ^5.0.0
- [@comunica/mediator-race](https://npm.io/package/@comunica/mediator-race.md) ^5.0.0
- [@comunica/bus-dereference](https://npm.io/package/@comunica/bus-dereference.md) ^5.0.0
- [@comunica/context-entries](https://npm.io/package/@comunica/context-entries.md) ^5.0.0
- [@comunica/mediator-number](https://npm.io/package/@comunica/mediator-number.md) ^5.0.0
- [@comunica/actor-http-fetch](https://npm.io/package/@comunica/actor-http-fetch.md) ^5.0.0
- [@comunica/actor-http-proxy](https://npm.io/package/@comunica/actor-http-proxy.md) ^5.0.0
- [@comunica/actor-rdf-parse-n3](https://npm.io/package/@comunica/actor-rdf-parse-n3.md) ^5.0.0
- [@comunica/bus-rdf-parse-html](https://npm.io/package/@comunica/bus-rdf-parse-html.md) ^5.0.0
- [@comunica/bus-dereference-rdf](https://npm.io/package/@comunica/bus-dereference-rdf.md) ^5.0.0
- [@comunica/config-query-sparql](https://npm.io/package/@comunica/config-query-sparql.md) ^5.0.0
- [@comunica/actor-rdf-parse-html](https://npm.io/package/@comunica/actor-rdf-parse-html.md) ^5.0.0
- [@comunica/actor-dereference-file](https://npm.io/package/@comunica/actor-dereference-file.md) ^5.0.0
- [@comunica/actor-dereference-http](https://npm.io/package/@comunica/actor-dereference-http.md) ^5.0.0
- [@comunica/actor-rdf-parse-jsonld](https://npm.io/package/@comunica/actor-rdf-parse-jsonld.md) ^5.0.0
- [@comunica/actor-rdf-parse-rdfxml](https://npm.io/package/@comunica/actor-rdf-parse-rdfxml.md) ^5.0.0
- [@comunica/actor-rdf-parse-shaclc](https://npm.io/package/@comunica/actor-rdf-parse-shaclc.md) ^5.0.0
- [@comunica/mediator-combine-union](https://npm.io/package/@comunica/mediator-combine-union.md) ^5.0.0
- [@comunica/actor-rdf-parse-xml-rdfa](https://npm.io/package/@comunica/actor-rdf-parse-xml-rdfa.md) ^5.0.0
- [@comunica/actor-rdf-parse-html-rdfa](https://npm.io/package/@comunica/actor-rdf-parse-html-rdfa.md) ^5.0.0
- [@comunica/mediator-combine-pipeline](https://npm.io/package/@comunica/mediator-combine-pipeline.md) ^5.0.0
- [@comunica/actor-dereference-fallback](https://npm.io/package/@comunica/actor-dereference-fallback.md) ^5.0.0
- [@comunica/actor-dereference-rdf-parse](https://npm.io/package/@comunica/actor-dereference-rdf-parse.md) ^5.0.0
- [@comunica/actor-rdf-parse-html-script](https://npm.io/package/@comunica/actor-rdf-parse-html-script.md) ^5.0.0
- [@comunica/actor-rdf-parse-html-microdata](https://npm.io/package/@comunica/actor-rdf-parse-html-microdata.md) ^5.0.0

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 5.0.0 (latest) — 2026-01-09
- 4.0.0 — 2024-10-15
- 3.0.0 — 2024-07-04
- 2.2.0 — 2023-08-07
- 2.1.0 — 2023-01-31
- 2.0.1 — 2022-11-09
- 2.0.0 — 2022-03-02
- 1.9.0 — 2021-08-30
- 1.8.0 — 2021-03-16
- 1.7.0 — 2021-01-15
- 1.6.0 — 2020-09-25
- 1.5.0 — 2020-04-18
- 1.4.1 — 2020-03-09
- 1.4.0 — 2020-01-29
- 1.3.1 — 2020-01-10
- … 5 more at https://npm.io/package/rdf-dereference/versions

## README

# RDF Dereference

[![Build status](https://github.com/rubensworks/rdf-dereference.js/workflows/CI/badge.svg)](https://github.com/rubensworks/rdf-dereference.js/actions?query=workflow%3ACI)
[![Coverage Status](https://coveralls.io/repos/github/rubensworks/rdf-dereference.js/badge.svg?branch=master)](https://coveralls.io/github/rubensworks/rdf-dereference.js?branch=master)
[![npm version](https://badge.fury.io/js/rdf-dereference.svg)](https://www.npmjs.com/package/rdf-dereference)

This library dereferences URLs to get its RDF contents.

This tool is useful in situations where you have a URL,
and you just need the _parsed triples/quads_,
without having to concern yourself with determining the correct content type and picking the correct parser.

RDF contents are returned as an _RDF stream_ with [RDFJS](http://rdf.js.org/)-compliant quads. If you would prefer a [`DatasetCore`](https://rdf.js.org/dataset-spec/#datasetcore-interface) return type see [rdf-dereference-store](https://www.npmjs.com/package/rdf-dereference-store).
This library takes care of all the necessary boilerplate automatically,
such as content negotiation for getting appropriate RDF serialization, decompression, following redirects, setting base URLs, and so on.
If the server did not emit any content type, then the content type will be guessed based on well-known extensions.

The following RDF serializations are supported:

| **Name**                                                                                                                                                                                 | **Content type** | **Extensions** |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| ---------------- | ------------- |
| [TriG 1.2](https://www.w3.org/TR/rdf12-trig/)                                                                                                                                            | `application/trig` | `.trig` |
| [N-Quads 1.2](https://www.w3.org/TR/rdf12-n-quads/)                                                                                                                                            | `application/n-quads` | `.nq`, `.nquads` |
| [Turtle 1.2](https://www.w3.org/TR/rdf12-turtle/)                                                                                                                                              | `text/turtle` | `.ttl`, `.turtle` |
| [N-Triples 1.2](https://www.w3.org/TR/rdf12-n-triples/)                                                                                                                                        | `application/n-triples` | `.nt`, `.ntriples` |
| [Notation3](https://www.w3.org/TeamSubmission/n3/)                                                                                                                                       | `text/n3` | `.n3` |
| [JSON-LD 1.1](https://json-ld.org/)                                                                                                                                                      | `application/ld+json`, `application/json` | `.json`, `.jsonld` |
| [RDF/XML 1.2](https://www.w3.org/TR/rdf12-xml/)                                                                                                                                 | `application/rdf+xml` | `.rdf`, `.rdfxml`, `.owl` |
| [RDFa 1.1](https://www.w3.org/TR/rdfa-in-html/) and script RDF data tags [HTML](https://html.spec.whatwg.org/multipage/)/[XHTML](https://www.w3.org/TR/xhtml-rdfa/)                      | `text/html`, `application/xhtml+xml` | `.html`, `.htm`, `.xhtml`, `.xht` |
| [Microdata](https://w3c.github.io/microdata-rdf/)                                                                                                                                        | `text/html`, `application/xhtml+xml` | `.html`, `.htm`, `.xhtml`, `.xht` |
| [RDFa 1.1](https://www.w3.org/TR/2008/REC-SVGTiny12-20081222/metadata.html#MetadataAttributes) in [SVG](https://www.w3.org/TR/SVGTiny12/)/[XML](https://html.spec.whatwg.org/multipage/) | `image/svg+xml`,`application/xml` | `.xml`, `.svg`, `.svgz` |
| [SHACL Compact Syntax](https://w3c.github.io/shacl/shacl-compact-syntax/)                                                                                                                | `text/shaclc` | `.shaclc`, `.shc` |
| [Extended SHACL Compact Syntax](https://github.com/jeswr/shaclcjs#extended-shacl-compact-syntax)                                                                                         | `text/shaclc-ext` | `.shaclce`, `.shce` |

Internally, this library makes use of RDF parsers from the [Comunica framework](https://github.com/comunica/comunica),
which enable streaming processing of RDF.

Internally, the following fully spec-compliant parsers are used:

* [N3.js](https://github.com/rdfjs/n3.js)
* [jsonld-streaming-parser.js](https://github.com/rubensworks/jsonld-streaming-parser.js)
* [microdata-rdf-streaming-parser.js](https://github.com/rubensworks/microdata-rdf-streaming-parser.js)
* [rdfa-streaming-parser.js](https://github.com/rubensworks/rdfa-streaming-parser.js)
* [rdfxml-streaming-parser.js](https://github.com/rdfjs/rdfxml-streaming-parser.js)
* [shaclcjs](https://github.com/jeswr/shaclcjs)

_If you need something more low-level with more control, have a look at [`rdf-parse`](https://github.com/rubensworks/rdf-parse.js#readme)._

## Installation

```bash
$ npm install rdf-dereference
```

or

```bash
$ yarn add rdf-dereference
```

This package also works out-of-the-box in browsers via tools such as [webpack](https://webpack.js.org/) and [browserify](http://browserify.org/).

## Require

```typescript
import { rdfDereferencer } from "rdf-dereference";
```

_or_

```javascript
const { rdfDereferencer } = require("rdf-dereference");
```

## Usage

### Dereferencing an RDF document

The `rdfDereferencer.dereference` method accepts an URL,
and outputs a promise resolving to an object containing a quad stream.

```javascript
const { data } = await rdfDereferencer.dereference('http://dbpedia.org/page/12_Monkeys');
data.on('data', (quad) => console.log(quad))
     .on('error', (error) => console.error(error))
     .on('end', () => console.log('All done!'));
```

Such a stream is useful when the RDF document is huge,
and you want to process it in a memory-efficient way.

Dereferencing works with any kind of RDF serialization,
even HTML documents containing RDFa and JSON-LD:

```javascript
const { data: quads1 } = await rdfDereferencer.dereference('https://www.rubensworks.net/');
const { data: quads2 } = await rdfDereferencer.dereference('https://www.netflix.com/title/80180182');
```

### Dereferencing a local file

Similar as above, the `rdfDereferencer.dereference` method also accepts file paths.

```javascript
const { data } = await rdfDereferencer.dereference('path/to/file.ttl', { localFiles: true });
data.on('data', (quad) => console.log(quad))
    .on('error', (error) => console.error(error))
    .on('end', () => console.log('All done!'));
```

Note that the `localFiles` flag MUST be enabled before local paths can be dereferenced for security reasons.

This feature is not available when this package is used within a browser environment.

### Importing the resulting quads into a store

These resulting quads can easily be stored in a [more convenient datastructure](http://rdf.js.org/stream-spec/#store-interface)
using tools such as [`rdf-store-stream`](https://www.npmjs.com/package/rdf-store-stream):

```javascript
import {storeStream} from "rdf-store-stream";
import {DataFactory} from "rdf-data-factory";

const dataFactory = new DataFactory();
const store = await storeStream(quads);

// Now you can do quad pattern queries over the stream, such as getting all triples having 'http://example.org/subject' as subject.
const resultStream = store.match(dataFactory.namedNode('http://example.org/subject'));
```

### Advanced features

#### Input: Passing custom headers

You can pass custom headers for the HTTP request via the options object:

```javascript
const { data } = await rdfDereferencer.dereference('https://www.netflix.com/title/80180182', {
  headers: {
    'Accept-Datetime': 'Thu, 31 May 2007 20:35:00 GMT',
  },
});
```

By default, the `GET` method will be used.

#### Input: Setting the HTTP method

You can define the HTTP method via the options object:

```javascript
const { data } = await rdfDereferencer.dereference('https://www.netflix.com/title/80180182', {
  method: 'POST',
});
```

By default, the `GET` method will be used.

#### Input: Using a custom fetch function

You can pass custom headers for the HTTP request via the options object:

```javascript
const { data } = await rdfDereferencer.dereference('https://www.netflix.com/title/80180182', {
  fetch: myFetch,
});
```

By default, the `GET` method will be used.

### Input: Handle unsupported versions

Since RDF 1.2, serializations support optional [version announcement](https://www.w3.org/TR/rdf12-concepts/#section-version-announcement)
to make parsers fail early on unsupported versions.

By default, this library is strict on its supported versions, and will emit an error on unsupported versions.
This behaviour can be disabled by setting `parseUnsupportedVersions` to `true`:

```javascript
const { data } = await rdfDereferencer.dereference('https://www.netflix.com/title/80180182', {
    parseUnsupportedVersions: true,
});
```

#### Output: Determining the final URL

If dereferencing went through various redirects, it may be useful to determine the final URL.
This can be done using the `url` field of the output object:

```javascript
const { data, url } = await rdfDereferencer.dereference('https://www.netflix.com/title/80180182');
console.log(url); // The final URL, e.g. https://www.netflix.com/at-en/title/80180182
```

#### Output: Response Headers

This library will return the HTTP response headers as a [Headers object](https://developer.mozilla.org/en-US/docs/Web/API/Headers):

```javascript
const { data, headers } = await rdfDereferencer.dereference('https://ruben.verborgh.org/profile/');
console.log(headers); // Example: new Headers({ 'content-length': '65701' })
```

#### Output: Triples or Quads

Some RDF serializations don't support named graphs, such as Turtle and N-Triples.
In some cases, it may be valuable to know whether or not an RDF document was serialized with such a format.
If this was the case, the `triples` flag will be set to true on the resulting object:

```javascript
const { quads, metadata } = await rdfDereferencer.dereference('https://ruben.verborgh.org/profile/');
console.log(metadata.triples); // If the document only supported triples, true in this case, since it returned Turtle.
```

### Command line usage

A CLI version of this tool exists, which can be installed globally as follows:

```bash
$ npm install -g rdf-dereference
```

After that, you can dereference any URL to a compact JSON-based quad representation:

```bash
$ rdf-dereference https://www.rubensworks.net/
[
{"subject":"https://www.rubensworks.net/","predicate":"http://xmlns.com/foaf/0.1/primaryTopic","object":"https://www.rubensworks.net/#me","graph":""},
{"subject":"https://www.rubensworks.net/","predicate":"http://xmlns.com/foaf/0.1/maker","object":"https://www.rubensworks.net/#me","graph":""},
{"subject":"https://www.rubensworks.net/#me","predicate":"http://www.w3.org/1999/02/22-rdf-syntax-ns#type","object":"http://xmlns.com/foaf/0.1/Person","graph":""},
{"subject":"https://www.rubensworks.net/#me","predicate":"http://xmlns.com/foaf/0.1/name","object":"\"Ruben Taelman\"","graph":""},
...
```

After that, you can dereference local files, for which the content type will be identified by extension:

```bash
$ rdf-dereference path/to/file.ttl
...
```

## License
This software is written by [Ruben Taelman](http://rubensworks.net/).

This code is released under the [MIT license](http://opensource.org/licenses/MIT).

---
_Source: https://npm.io/package/rdf-dereference · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
