DefinitelyTyped/types/sparql-http-client/sparql-http-client-tests.ts
Tomasz Pluskiewicz a136c9f181 refactor: sparql-http-client updated to use correct exports (#39966)
* fix: sparql-http-client should use built-in fetch

* fix: disable tslint rule to accommodate for commonjs default export

* revert default export

* change export syntax
2019-10-29 14:00:37 -07:00

42 lines
1.1 KiB
TypeScript

import * as SparqlHttp from 'sparql-http-client';
const client = new SparqlHttp();
async function selectQuery() {
const response = await client.selectQuery('...', {
endpointUrl: 'http://example.com/endpoint',
});
const json = await response.json();
json.results.bindings.forEach(binding => {
console.log(`${binding.name.value} (${binding.name.termType})`);
});
}
async function askQuery() {
const response = await client.selectQuery('...', {
endpointUrl: 'http://example.com/endpoint',
});
const json = await response.json();
console.log(`The answer was ${json.boolean ? 'YES' : 'NO'}`);
}
async function constructQuery() {
const response = await client.constructQuery('...');
const json = await response.json();
console.log(`The answer was ${json.boolean ? 'YES' : 'NO'}`);
}
async function updateQuery() {
const response = await client.constructQuery('...', {
updateUrl: 'http://example.com/endpoint',
});
console.log(`The update ${response.ok ? 'succeeded' : 'faield'}`);
}