PHP code example of joshuaify / guzzlelib
1. Go to this page and download the library: Download joshuaify/guzzlelib 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/ */
joshuaify / guzzlelib example snippets
use joshuaify\API\Guzzlelib;
$guzzlelib = new Guzzlelib([
'base_uri' => 'https://api.example.com',
'timeout' => 30.0,
'headers' => [
'Authorization' => 'Bearer your-token-here'
]
]);
$response = $guzzlelib->getRequest('/users', ['page' => 1]);
$response = $guzzlelib->postRequest('/users', [
'name' => 'John Doe',
'email' => '[email protected] '
]);
$response = $guzzlelib->putRequest('/users/1', [
'name' => 'Jane Doe'
]);
$response = $guzzlelib->patchRequest('/users/1', [
'email' => '[email protected] '
]);
$response = $guzzlelib->deleteRequest('/users/1');
$response = $guzzlelib->getRequest('/users');
if ($response['code'] === 200) {
$users = $response['body'];
// Process $users data
} else {
// Handle error
echo "Error: " . json_encode($response['body']);
}
$response = $guzzlelib->getRequest('/non-existent-endpoint');
if (isset($response['error']) && $response['error'] === true) {
echo "Error occurred: " . $response['message'];
}