Skip to content

Commit

Permalink
Create javascript_snippets.md
Browse files Browse the repository at this point in the history
  • Loading branch information
baddonkey committed Mar 23, 2023
1 parent 3b91722 commit 40f4e44
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions javascript_snippets.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
## LINDAS, use POST request, x-www-form-urlencoded and json as result
```javascript
let queryBody = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " +
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> " +
" SELECT * WHERE { " +
"?sub_1 <https://www.ica.org/standards/RiC/ontology#hasRecordSetType> ?all. " +
"VALUES ?all {<https://culture.ld.admin.ch/ais/vocabularies/recordSetTypes/1> <https://culture.ld.admin.ch/ais/vocabularies/recordSetTypes/10001> <https://culture.ld.admin.ch/ais/vocabularies/recordSetTypes/10003> } " +
" ?sub_1 <https://www.ica.org/standards/RiC/ontology#title> ?title. " +
" ?sub_1 <https://www.ica.org/standards/RiC/ontology#hasRecordSetType> ?level. " +
"} LIMIT 1000000";

var details = {
'query': queryBody,
'lang': 'de'
};

var formBody = [];
for (var property in details) {
var encodedKey = encodeURIComponent(property);
var encodedValue = encodeURIComponent(details[property]);
formBody.push(encodedKey + "=" + encodedValue);
}
formBody = formBody.join("&");

var url = "https://lindas.admin.ch/query";

async function asyncCall() {
let response = await fetch(
url,
{
method: 'POST',
headers: {
'accept' : "application/sparql-results+json,*/*;q=0.9",
'content-type' : "application/x-www-form-urlencoded"
},
body: formBody
}
);
let responsetext = await response.text();
console.log(responsetext);
let adapteddata = adaptdata(responsetext);
visualizedata(adapteddata);
}
```

0 comments on commit 40f4e44

Please sign in to comment.