DefinitelyTyped/types/sparql-http-client/sparql-http-client-tests.ts
Tomasz Pluskiewicz 7ea9422586 added typings for sparql-http-client (#38915)
* added typings for sparql-http-client

* use readonly array for select result
2019-10-08 16:07:05 -07:00

42 lines
1.1 KiB
TypeScript

import { 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'}`);
}