Have ideas to improve npm?Join in the discussion! »

sparql-http-client
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/sparql-http-client package

2.2.3 • Public • Published

sparql-http-client

Build Status NPM Version

SPARQL client for easier handling of SPARQL Queries and Graph Store requests. The SPARQL Protocol is used for SPARQL Queries and SPARQL Updates. The SPARQL Graph Store Protocol is used to manage Named Graphs.

Getting started example

TL;DR; the package exports a StreamClient class which run SPARQL queries on an endpoint.

const SparqlClient = require('sparql-http-client')

const endpointUrl = 'https://query.wikidata.org/sparql'
const query = `
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>

SELECT ?value WHERE {
  wd:Q243 p:P2048 ?height.

  ?height pq:P518 wd:Q24192182;
    ps:P2048 ?value .
}`

const client = new SparqlClient({ endpointUrl })
const stream = await client.query.select(query)

stream.on('data', row => {
  Object.entries(row).forEach(([key, value]) => {
    console.log(`${key}: ${value.value} (${value.termType})`)
  })
})

stream.on('error', err => {
  console.error(err)
})

Find more details on https://zazuko.github.io/sparql-http-client

URL class

This library uses the URL class of universal-url. Please see universal-url-lite for optimized browser builds.

Install

npm i sparql-http-client

DownloadsWeekly Downloads

988

Version

2.2.3

License

MIT

Unpacked Size

167 kB

Total Files

41

Last publish

Collaborators

  • avatar
  • avatar
  • avatar