Registry / http-networking / sparql-http-client

sparql-http-client

JSON →
library3.1.0jsnpmunverified

sparql-http-client is a JavaScript client library designed to simplify interactions with SPARQL endpoints, covering SPARQL Queries, Updates, and Graph Store operations. It abstracts the complexities of the SPARQL Protocol and SPARQL Graph Store Protocol, offering a streamlined API. The current stable version is 3.1.0, and the project appears to be actively maintained, indicated by recent version updates and a healthy GitHub repository. A key differentiator is its provision of multiple client 'flavors': the default `SparqlClient` (also known as `StreamClient`) which leverages Node.js streams for processing results from `SELECT`, `CONSTRUCT`, and `DESCRIBE` queries; a `SimpleClient` that aligns more closely with the `fetch` API for direct response handling; and a `ParsingClient` that automatically wraps results into RDF/JS DatasetCore objects or arrays. This flexibility allows developers to choose the most suitable interface for their specific use case, whether it's processing large result sets via streams or quickly retrieving parsed RDF data.

npm install sparql-http-client
INSTALL
IMPORT
SIG · SPARQL-HTTP-CLIENT
S
sparql-http-client
http-networkingjavascriptv3.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

SparqlClient
import SparqlClient from 'sparql-http-client'
const SparqlClient = require('sparql-http-client')
The primary client, which defaults to streaming behavior. CommonJS `require` is not supported since v3.
SimpleClient
import { SimpleClient } from 'sparql-http-client'
import SimpleClient from 'sparql-http-client'
For a simpler, fetch-like client that returns raw HTTP responses. This is a named export, not a default.
ParsingClient
import { ParsingClient } from 'sparql-http-client'
Provides automatic parsing of SPARQL results into RDF/JS DatasetCore objects or arrays. This is a named export.

This example demonstrates how to initialize the default `SparqlClient`, execute a `SELECT` query against a public SPARQL endpoint (Wikidata), and process the streaming results asynchronously. It logs each binding from the result rows.

import SparqlClient from '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 . }` async function runQuery() { const client = new SparqlClient({ endpointUrl }) const stream = await client.query.select(query) return new Promise((resolve, reject) => { stream.on('data', row => { for (const [key, value] of Object.entries(row)) { console.log(`${key}: ${value.value} (${value.termType})`) } }) stream.on('end', () => { console.log('Query finished.') resolve() }) stream.on('error', err => { console.error('Stream error:', err) reject(err) }) }) } runQuery().catch(console.error)
Debug
Known issues
breakingVersion 3.x of `sparql-http-client` transitioned to being an ESM-only package. Direct `require()` statements for importing the library will no longer work, leading to runtime errors.
fix
Migrate your project to use ES modules (`import`/`export`) or use dynamic `import()` for CommonJS contexts, if absolutely necessary, though direct `require` is not supported.
affects: >=3.0.0
gotchaAll client constructors (`SparqlClient`, `SimpleClient`, `ParsingClient`) require at least one URL argument (`endpointUrl`, `updateUrl`, or `storeUrl`) in their options object. Omitting all of them will result in an error or disable specific capabilities.
fix
Ensure the client is initialized with at least one URL, for example: `new SparqlClient({ endpointUrl: 'http://example.org/sparql' })`.
affects: >=1.0.0
gotchaDifferent query types return different result formats and mechanisms. `client.query.select()` and `client.query.construct()` return Node.js readable streams, which must be consumed (e.g., using `stream.on('data')` or `for await...of`). `client.query.ask()` and `client.query.update()` return Promises that resolve to a boolean or void, respectively.
fix
Always check the return type for the specific query operation. For streams, ensure proper stream consumption. For Promises, use `await` or `.then()` to handle the result.
affects: >=1.0.0
Errors
Common errors & fixes
ReferenceError: require is not defined
`sparql-http-client` version 3.x and above is an ES module and does not support CommonJS `require` syntax directly.
fix
Change your import statements from `const SparqlClient = require('sparql-http-client')` to `import SparqlClient from 'sparql-http-client'` and ensure your project is configured for ES modules (e.g., `"type": "module"` in `package.json`).
TypeError: Missing 'endpointUrl' option
The `SparqlClient` (or other client variants) constructor was called without providing the necessary `endpointUrl` (or `updateUrl`/`storeUrl`) in the configuration object.
fix
Provide the SPARQL endpoint URL when initializing the client: `const client = new SparqlClient({ endpointUrl: 'https://query.wikidata.org/sparql' })`.
No data received from SPARQL SELECT query stream
When using `client.query.select()` or `client.query.construct()`, the method returns a Node.js readable stream. If the stream is not actively consumed (e.g., listening for 'data' events or using async iterators), no data will be processed.
fix
Ensure you are consuming the stream by attaching 'data' event listeners and an 'end' listener, or by using `for await (const row of stream)` if your environment supports async iterators.
Upgrade
Version history
3.1.0latest on npm
Audit
Dependencies
@rdfjs/environmentrequiredRequired for RDF/JS environment setup and data factories.
@rdfjs/typesrequiredProvides core RDF/JS TypeScript interfaces for data models and datasets.
readable-streamrequiredUsed by the default StreamClient for handling SPARQL query results as Node.js streams.
node-fetchrequiredProvides a fetch API implementation for Node.js environments, especially for versions prior to native fetch support.
Agent activity
11 hits · last 30 days
node
10
OpenAI (training)
1
Resources
sparql-http-client — npm install sparql-http-client · libregistry