Skip to content

rpungello/sdk-client

Repository files navigation

PHP SDK Client

Latest Version on Packagist Tests Total Downloads

Generic client for creating PHP-based SDKs using Spatie's DTOs for data transfer.

Installation

You can install the package via composer:

composer require rpungello/sdk-client

Usage

Instantiate the client

$client = new Rpungello\SdkClient('https://example.com');

GET requests

// 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);

PUT/POST/PATCH requests

// Returns a Psr\Http\Message\ResponseInterface response
$response = $client->post('/api/v1/users', [
    'name' => 'John Doe',
    'email' => 'john@example.com',
]);

// Returns a json-decoded array from the response body
$response = $client->postJson('/api/v1/users', [
    'name' => 'John Doe',
    'email' => 'john@example.com',
]);

// Takes the JSON data returned and wraps it in a DTO for static typing
$user = new UserDto([
    'name' => 'John Doe',
    'email' => 'john@example.com',
]);
$response = $client->postDto('/api/v1/users', $user);

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

About

Generic client for creating PHP-based SDKs using Spatie's DTOs for data transfer

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •