1. Go to this page and download the library: Download noc-vissor/papi library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use NocVissor\Papi\Request;
$request = new Request();
$request->post['data'] = 'somebody';
use NocVissor\Papi\Request;
$request1 = new Request([
'post' => [
'par1' => 'val1',
'par2' => 'val2'
]
]);
$request2 = new Request([
'post' => [
'par2' => 'newVal2',
'par3' => 'val3'
]
]);
// request2 passed by first parametr, so request2 has hightly priotity than request1
$new_request = Request::merge($request2, $request1);
print_r($new_request);
// [post] => Array
// (
// [par2] => newVal2
// [par3] => val3
// [par1] => val1
// )
use NocVissor\Papi\Request;
use NocVissor\Papi\Auth\Auth;
use NocVissor\Papi\Api;
class TokenAuth extends Auth{
private $token;
function __construct($token)
{
parent::__construct();
$this->token = $token;
$this->request = new Request([
'headers' => [
'token' => $token
]
]);
}
protected function link(Api $api){
parent::link($api);
$api->base_url = "https://site.com/api/$this->token"
}
}
$api = new Api();
$token = 'token';
$auth = new TokenAuth($token);
$api->auth($auth);
use NocVissor\Papi\Request;
use NocVissor\Papi\Auth\BearerAuth;
use NocVissor\Papi\Api;
$api = new Api('https://example.com/api');
// create bearer token auth
$auth = new BearerAuth('token');
// link auth object to api object
$api->auth($auth);
// set base request
$api->setBase(new Request(['get'=>[
'a' => 'b'
]]));
// merge base request (original base request has priotity on passed request)
$api->mergeBase(new Request(['get'=>[
'a' => 'c',
'222' => 'ttt'
]]));
// result $api->based_request->get['a'] - b
// put, post, get, patch, delete methods accept url relative base_url and request object
$api->put('/items/add', new Request([
'post' => [
'name' => 'test_name'
]
]));
use NocVissor\Papi\Request;
use NocVissor\Papi\Api;
$api = new Api('https://example.com/api');
$custom_ch = curl_init();
curl_setopt($custom_ch, CURLOPT_EXPECT_100_TIMEOUT_MS, 100000);
$api->query([
'url' => 'https://example.com/api2/items/add', //
use NocVissor\Papi\Api;
$api = new Api();
$api->cache->setPath('../../path');
$api->cache->put('token.json', json_encode([
'access' => 'aaa',
'refresh' => 'bbb'
]));
$file = $api->cache->get('token.json');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.