-
Notifications
You must be signed in to change notification settings - Fork 0
Home
This package allows you to quickly build a robust SDK client to interact with a remote API. It is heavily inspired by Guzzle Services.
It begins with a service description, which is a PHP array documenting the remote service. It includes the operations, parameters, validation rules, and optionally caching and circuit breaker parameters.
Here is a super simple example calling a mock endpoint and retrieving an array response;
$description = [
"name" => "Quick Example",
"baseUrl" => "http://mockbin.org",
"operations" => [
"doSomething" => [
"httpMethod" => "GET",
"uri" => "/bin/2af3d6c1-a7bc-4efa-aad9-09ea25515272",
]
]
];
$client = new \STS\Sdk\Client($description);
$result = $client->doSomething();
// $result is now ["success" => true]
Of course a real world operation would have parameters, validation rules, and more.
If you peruse the source code you'll notice a number of Laravel components being used. I used the Laravel Container to build classes and auto-resolve dependencies, for example. Laravel validation is used for parameter rules, the pipeline is used for processing a request with a middleware pattern, etc.
There is however no strong dependency on the Laravel framework as whole. I've only cherry-picked some components that were useful, and ensure this package can be used outside of Laravel.
When an operation is processed it is passed through a pipeline of middleware classes. It is easy to add your own custom pipeline steps. This would be an easy way to automatically add authentication headers, for example.
The main Client class is made to be extended, if you want to handle certain steps (like Description file discovery) based on a convention instead of handing in arrays manually.