Update API
parent
75b6118b9f
commit
73ff9f871d
1 changed files with 29 additions and 15 deletions
44
API.md
44
API.md
|
@ -61,23 +61,37 @@ var_dump($result);
|
|||
<html>
|
||||
<head>
|
||||
<script>
|
||||
function pandora_api(action, data, callback) {
|
||||
var url = 'http://archive.arabdigitalexpression.org/api/';
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.addEventListener('load', function (evt) {
|
||||
var data = JSON.parse(evt.target.responseText);
|
||||
callback(data);
|
||||
});
|
||||
var formData = new FormData();
|
||||
formData.append('action', action);
|
||||
formData.append('data', JSON.stringify(data));
|
||||
xhr.open('POST', url);
|
||||
xhr.send(formData);
|
||||
async function api(action, data) {
|
||||
const url = "https://pad.ma/api/"
|
||||
var response = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
action: action,
|
||||
data: data
|
||||
})
|
||||
})
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
pandora_api('find', {query: ....}, function(result) {
|
||||
console.log(result)
|
||||
});
|
||||
|
||||
api('find', {
|
||||
query: {
|
||||
conditions: [
|
||||
{key: 'title', operator: '=', value: 'A Day'}
|
||||
]
|
||||
},
|
||||
keys: ['id', 'title', 'summary'],
|
||||
range: [0, 10]
|
||||
}).then(result => {
|
||||
result.data.items.forEach(item => {
|
||||
const div = document.createElement("div")
|
||||
div.innerHTML = `<h1><a href="https://pad.ma/${item.id}">${item.title}</a></h1><p>${item.summary}</p>`
|
||||
document.body.appendChild(div)
|
||||
})
|
||||
})
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
|
Loading…
Reference in a new issue