A simple to use SDK builder for PHP. This package is still in beta - but there should be no breaking changes.
Via Composer
$ composer require suitcasephp/builder
Building the SDK
use Suitcase\Builder\SDK;
$sdk = new SDK('https://api.example.com');
Adding Resources to the SDK:
$sdk->add('posts', [
'endpoint' => 'posts',
'allows' => [
'get', 'find', 'create', 'update', 'delete'
]
]);
If you want to pass in a resource that follows the defaults:
$sdk->add('posts');
What this will do is use the string passed in as a name and an endpoint, and pass through the default allows options - basically allowing all operations.
Selecting a resource is pretty simple:
$sdk->use('posts');
What this will do is set the active resource on the SDK allowing you to use the allowed actions. A MethodNotAllowed
is throw if the action is not registered in the allows
array on the resource.
Performing actions on a resource:
$sdk->use('posts')->get(); // return all posts
$sdk->use('posts')->find(1); // return the post with an identifier of 1
$sdk->use('posts')->create([]); // create a new post
$sdk->use('posts')->update(1, []); // update a post with an identifier of 1
$sdk->use('posts')->delete(1); // delet the post with a identifier of 1