PHP code example of agsystemspl / abstract-rest-client
1. Go to this page and download the library: Download agsystemspl/abstract-rest-client 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/ */
agsystemspl / abstract-rest-client example snippets
use AGSystemsPl\RestClient\AbstractClient;
class MyApiClient extends AbstractClient
{
protected function clientOptions(): array
{
return [
'base_uri' => 'https://api.example.com/v1/'
];
}
}
$client = new MyApiClient();
// Fluent path and method chaining
$response = $client->users->123->get(['format' => 'json']);
// GET request
$client->users->get();
// POST request with JSON body
$client->users->post(['name' => 'John']);
// PUT request
$client->users->123->put(['name' => 'Updated']);
// DELETE request
$client->users->123->delete();
// Set initial options
$client = new MyApiClient([
'timeout' => 10,
'verify' => false
]);
// Replace all options
$client->withOptions(['new' => 'configuration']);
// Merge additional options
$client->appendOptions(['extra' => 'settings']);
class MyCustomClient extends AbstractClient
{
// Override path handling
protected function handlePath($segments): string
{
// Custom path processing logic
return parent::handlePath($segments);
}
// Custom response processing
protected function handleResponse($response)
{
// Custom logic, e.g., XML parsing
return $response;
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.