1. Go to this page and download the library: Download mnapoli/bof 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/ */
mnapoli / bof example snippets
// Bof
$http = new Bof\Http;
$createdProduct = $http
->withHeader('Authorization', 'Token abcd')
->postJson('https://example.com/api/products', [
'Hello' => 'world',
])
->getData();
// Guzzle
$client = new GuzzleHttp\Client([
'headers' => [
'Authorization' => 'Token abcd',
],
]);
$response = $client->request('POST', 'https://example.com/api/products', [
'json' => [
'Hello' => 'world',
]
]);
$createdProduct = json_decode($response->getBody()->__toString(), true);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new Exception('There was an error while decoding the JSON response');
}
$http = new Bof\Http;
$response = $http->get('https://example.com/api/products');
$http = new Bof\Http;
// The header will apply to all subsequent requests
$http = $http->withHeader('Authorization', "Bearer $token");
$http1 = new Bof\Http;
$http2 = $http1->withHeader('Authorization', "Bearer $token");
// $http1 does not have the header applied
// $http2 has the header
$products = $http->withHeader('Authorization', "Bearer $token")
->get('https://example.com/api/products')
->getData();
// The next requests will *not* have the `Authorization` header
$http = new Bof\Http;
$products = $http->get('https://example.com/api/products')
->getData();
$http = $http->withMultipleProxies(
'tcp://localhost:8125', // Use this proxy with HTTP
'tcp://localhost:9124', // Use this proxy with HTTPS
['.mit.edu', 'foo.com'] // Don't use a proxy with these
);
$guzzleClient = new GuzzleHttp\Client([
'base_uri' => 'http://httpbin.org',
'timeout' => 2.0,
]);
$http = new Bof\Http($guzzleClient);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.