1. Go to this page and download the library: Download forsaken-threads/diplomatic 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/ */
forsaken-threads / diplomatic example snippets
use ForsakenThreads\Diplomatic\Client;
$client = new Client('http://api.example.com');
// a simple get, and we don't care about the response
$client->get('/endpoint/url');
// a simple get, and we just want the raw response text
$client-get('/endpoint/url')->saveRawResponse($response);
echo $response;
// a simple post, and we'll save the response handler to inspect
$client->post('/endpoint/url', ['id' => 123])
->saveResponseHandler($handler);
if ($handler->wasSuccessful()) {
echo "such API, much success";
} else {
echo "bad juju";
}
// now for some JSON requests
$client->addHeaders(['Content-type' => 'text/json']);
// make two posts and save each handler
$client->post('/endpoint/url?json', json_encode(['id' => 123])->saveResponseHandler($handler1)
->post('/endpoint/url?json', json_encode(['id' => 456])->saveResponseHandler($handler2);
if ($handler1->wasSuccessful() && $handler2->wasSuccessful()) {
echo "that's a two-fer!";
} else {
echo "no go";
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.