godmodelabs / flora-client-php
PHP client for Flora based APIs
Installs: 1 274
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 13
Forks: 0
Open Issues: 0
Requires
- php: ^7.3 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0
- ext-json: *
- guzzlehttp/guzzle: ^7.4
Requires (Dev)
- http-interop/http-factory-guzzle: ^1.0
- phpunit/phpunit: ^9.0 || ^10.5
README
Easily access Flora based APIs.
$client = new \Flora\Client('http://api.example.com/'); $response = $client->execute([ 'resource' => 'foo', 'select' => 'id,name' ]);
Raw responses
Return PSR-7 response object (e.g. to handle binary data).
$client = new \Flora\Client('http://api.example.com/'); $response = $client->executeRaw([ 'resource' => 'article', 'id' => 1337, 'action' => 'pdf', ]);
Asynchronous requests (using guzzlehttp/promises
)
use GuzzleHttp\Promise; $client = new \Flora\Client('http://api.example.com/'); try { $fooPromise = $client->executeAsync([ 'resource' => 'foo', 'select' => 'id,name' ]); $barPromise = $client->executeAsync([ 'resource' => 'bar', 'select' => 'id,name' ]); [$fooResponse, $barResponse] = Promise\Utils::unwrap([$fooPromise, $barPromise]); // process responses... } catch (Throwable $e) { echo $e->getMessage(), PHP_EOL; }
Parallel requests
Simple interface for simultaneously executing multiple API requests. Basically hides complexity from example above.
$client = new \Flora\Client('http://api.example.com/'); try { [$fooResponse, $barResponse] = $client->executeParallel([ ['resource' => 'foo', 'select' => 'id,name'], ['resource' => 'bar', 'select' => 'id,name'] ]); // process responses... } catch (Throwable $e) { echo $e->getMessage(), PHP_EOL; }