PHP code example of paulbunyannet / api

1. Go to this page and download the library: Download paulbunyannet/api 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/ */

    

paulbunyannet / api example snippets


$getArgs = ['something' => ,'something_else']; 
$get = new Get('https://pathtoapi.com/get/?'.http_build_query($getArgs));
$retrieve = $get->retrieve();
var_dump($retrieve); // { "some_response_key" => "some_response_value" }

$getArgs = ['something' => ,'something_else']; 
$get = new Get('https://pathtoapi.com/get/?'.http_build_query($getArgs));
$retrieve = $get->retrieve();
var_dump($retrieve); // { "some_response_key" => "some_response_value" }

$postArgs = ['something' => ,'something_else']; 
$post = new Post('https://pathtoapi.com/post');
$retrieve = $post->retrieve($postArgs);
var_dump($retrieve); // { "some_response_key" => "some_response_value" }

$postArgs = ['something' => ,'something_else']; 
$put = new Put('https://pathtoapi.com/put');
$retrieve = $put->retrieve($postArgs);
var_dump($retrieve); // { "some_response_key" => "some_response_value" }

$delete = new Put('https://pathtoapi.com/delete/user/1');
$retrieve = $delete->retrieve();
var_dump($retrieve); // { "success" => "true" }

$getArgs = ['something' => ,'something_else']; 
$get = new Get('https://pathtoapi.com/get/?'.http_build_query($getArgs));
// headers to pass with request
$get->setHeaders(['headerKey' => 'headerValue']);
$retrieve = $get->retrieve();
var_dump($retrieve); // { "some_response_key" => "some_response_value" }

// on the sender side:
$postArgs = ['something' => ,'something_else'];
$identity = 'my-user-name'; // used for looking up private key on the receiving side
$privateKey = "my-super-secret-key";
$post = new Post('https://pathtoapi.com/post');
$post->setPayload([Auth\AuthBootstrap::IDENTITY => $identity, Auth\AuthBootstrap::PRIVATEKEY => $privateKey]);
$retrieve = $post->retrieve($postArgs);

// then on the receiving side:
$lookUpPrivateKey = 'my-super-secret-key'; // this is where you would do a lookup for user's private key by the ideney key that was sent with the request
$receiver = new Auth\Receive($_POST['payload'], $lookUpPrivateKey);
$verifyHash = receiver->verifyHash($_POST); // will return true if payload hash sent is correct