Update API

j 2024-06-22 08:23:23 +00:00
parent 73ff9f871d
commit 66437d47aa

85
API.md

@ -13,48 +13,6 @@ To use the API you can use Ox.App if you use Ox.js, or look at [pandora_client](
### Examples ### Examples
#### PHP
```
<?php
class API {
function __construct($url) {
$this->url = $url;
}
public function _request($action, $data) {
$content = array(
'action' => $action,
'data' => json_encode($data)
);
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($content),
),
);
$context = stream_context_create($options);
$result = json_decode(file_get_contents($this->url, false, $context));
return $result;
}
}
l
$api = new API('http://archive.arabdigitalexpression.org/api/');
$result = $api->_request('find', array(
"query"=>array(
"conditions"=>array(array("key"=>"*", "value"=>"paris", "operator"=>'='))
),
"keys"=>array("title", 'id'),
"range"=> array(0, 10),
"sort"=>array(array("key"=>"title", "operator"=>"+"))
));
var_dump($result);
```
#### JavaScript #### JavaScript
``` ```
<!DOCTYPE html> <!DOCTYPE html>
@ -160,3 +118,46 @@ for i in api.find({'query': {
print id print id
api.edit({'id': i['id'], 'groups': groups}) api.edit({'id': i['id'], 'groups': groups})
``` ```
#### PHP
```
<?php
class API {
function __construct($url) {
$this->url = $url;
}
public function _request($action, $data) {
$content = array(
'action' => $action,
'data' => json_encode($data)
);
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($content),
),
);
$context = stream_context_create($options);
$result = json_decode(file_get_contents($this->url, false, $context));
return $result;
}
}
l
$api = new API('http://archive.arabdigitalexpression.org/api/');
$result = $api->_request('find', array(
"query"=>array(
"conditions"=>array(array("key"=>"*", "value"=>"paris", "operator"=>'='))
),
"keys"=>array("title", 'id'),
"range"=> array(0, 10),
"sort"=>array(array("key"=>"title", "operator"=>"+"))
));
var_dump($result);
```