※日本語での解説記事はこちら
ajv
>= 8.8.0
import { JSONResponseIsValid } from './validator'
const endpoint = 'https://dbpedia.org/sparql'
const query = `
SELECT * WHERE {
?sub ?pred ?obj .
} LIMIT 10
`
const url = `${endpoint}?query=${encodeURIComponent(query)}`
fetch(url)
.then(response => {
const data = response.json()
if (!JSONResponseIsValid(data)) {
throw new Error('Invalid SPARQL JSON Response.')
} else {
return data
}
})
.catch((error) => {
console.error('Error:', error);
})
or Demo Application on StackBlitz
If you are using a language such as Python, Ruby, Java, Golang, C# or even Rust, you can refer to the following implementations.
By reusing the predefined schemas below, type-safe implementations can be expected in each language.
SPARQL 1.1 Query Result JSON Format