{"library":"sparql-http-client","title":"SPARQL HTTP Client","type":"library","description":"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.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install sparql-http-client"],"cli":null},"imports":["import SparqlClient from 'sparql-http-client'","import { SimpleClient } from 'sparql-http-client'","import { ParsingClient } from 'sparql-http-client'"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":"https://rdf-ext.github.io/sparql-http-client/","github":"https://github.com/rdf-ext/sparql-http-client","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/sparql-http-client","openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"import SparqlClient from 'sparql-http-client'\n\nconst endpointUrl = 'https://query.wikidata.org/sparql'\nconst query = `\nPREFIX wd: <http://www.wikidata.org/entity/>\nPREFIX p: <http://www.wikidata.org/prop/>\nPREFIX ps: <http://www.wikidata.org/prop/statement/>\nPREFIX pq: <http://www.wikidata.org/prop/qualifier/>\n\nSELECT ?value WHERE {\n  wd:Q243 p:P2048 ?height.\n\n  ?height pq:P518 wd:Q24192182;\n    ps:P2048 ?value .\n}`\n\nasync function runQuery() {\n  const client = new SparqlClient({ endpointUrl })\n  const stream = await client.query.select(query)\n\n  return new Promise((resolve, reject) => {\n    stream.on('data', row => {\n      for (const [key, value] of Object.entries(row)) {\n        console.log(`${key}: ${value.value} (${value.termType})`)\n      }\n    })\n\n    stream.on('end', () => {\n      console.log('Query finished.')\n      resolve()\n    })\n\n    stream.on('error', err => {\n      console.error('Stream error:', err)\n      reject(err)\n    })\n  })\n}\n\nrunQuery().catch(console.error)\n","lang":"typescript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}