Generic client for creating PHP-based SDKs using Spatie's DTOs for data transfer.
You can install the package via composer:
composer require rpungello/sdk-client
$client = new Rpungello\SdkClient('https://example.com');
// Returns a Psr\Http\Message\ResponseInterface response
$response = $client->get('/api/v1/users');
// Specify a query string
$response = $client->get('/api/v1/users', [
'page' => 1,
'limit' => 10,
]);
// Returns a json-decoded array from the response body
$response = $client->getJson('/api/v1/users');
// Takes the JSON data returned and wraps it in a DTO for static typing
$response = $client->getDto('/api/v1/users/1', UserDto::class);
// Takes the JSON data returned and converts it to an array of DTOs for static typing
$response = $client->getDtoArray('/api/v1/users', UserDto::class);
// Returns a Psr\Http\Message\ResponseInterface response
$response = $client->post('/api/v1/users', [
'name' => 'John Doe',
'email' => '[email protected]',
]);
// Returns a json-decoded array from the response body
$response = $client->postJson('/api/v1/users', [
'name' => 'John Doe',
'email' => '[email protected]',
]);
// Takes the JSON data returned and wraps it in a DTO for static typing
$user = new UserDto([
'name' => 'John Doe',
'email' => '[email protected]',
]);
$response = $client->postDto('/api/v1/users', $user);
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.