Readme

Query Wikidata via SPARQL

Usage

// get the death date for a person @stevekrouse.wikidata(`SELECT ?person ?personLabel ?death_date WHERE { ?person rdfs:label "Henry Kissinger"@en; wdt:P31 wd:Q5 . # Ensure the entity is a human OPTIONAL { ?person wdt:P570 ?death_date . # Try to find a date of death } SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } }`)

Learn more

1
2
3
4
5
6
7
8
9
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
export function wikidata(sparql: string) {
return fetchJSON(
"https://query.wikidata.org/sparql" + "?query=" +
encodeURIComponent(sparql),
{ headers: { accept: "application/sparql-results+json" } },
);
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023