[Deprecated and Unmaintained]
Simple Guzzle configurator using client configuration and api descriptions files.
- All you have to do is to create two files :
- the Guzzle client configuration (api url, version, user agent, etc.)
- the API description structure
- use
ZeppelinFactory
factory or create your own - consume APIs
Zeppelin aim to let you focus on your main project by providing a simple and easy way to consume api and web services.
you can install zeppelin using composer
$ composer require fnayou/zeppelin
- create your Guzzle client configuration file based on the configuration sample file
- create your API description file based on the api description sample file
- use the
ZeppelinFactory
factory with your favoriteLoader
(more loaders will be released soon)
<?php
use Fnayou\Zeppelin\Factory\ZeppelinFactory;
use Fnayou\Zeppelin\Loader\YamlLoader;
$yamlLoader = YamlLoader();
$configurationFilePath = '/path/to/api_configuration.yml';
$customGuzzleConfiguration = [];
$client = ZeppelinFactory::build($yamlLoader, $configurationFilePath, $customGuzzleConfiguration);
- consume your APIs
<?php
// you can access api as method (according to the api description file)
try {
$response = $client->user([
'X-APPID' => '26041986',
'user_id' => 26,
]);
} catch (\GuzzleHttp\Exception\RequestException $e) {
$response = json_decode($e->getResponse()->getBody()->getContents());
}
dump($response);
- you can also create you own
factory
with your own logic, all you have to do is implementFactoryInterface
<?php
namespace Vendor\App\Factory;
use Fnayou\Zeppelin\ApiClient;
use Fnayou\Zeppelin\Api\ApiDescription;
use Fnayou\Zeppelin\Factory\FactoryInterface;
use Fnayou\Zeppelin\Loader\LoaderInterface;
use GuzzleHttp\Client;
use GuzzleHttp\Command\Guzzle\GuzzleClient;
class CustomFactory implements FactoryInterface
{
public static function build(LoaderInterface $loader, $filePath, array $config)
{
// load the guzzle configuration file
$apiClientConfiguration = new ApiClient($loader, $filePath);
// load the api description file
$apiDescription = new ApiDescription(
$loader,
$apiClientConfiguration->getDescriptionFilePath()
);
$client = new Client($apiClientConfiguration->getClientConfiguration());
// your guzzle instance using api description, and custom configuration
$zeppelin = new GuzzleClient(
$client,
$apiDescription->getDescription(),
$config
);
return $zeppelin;
}
}
Please see CONTRIBUTING and CONDUCT for details.
- Aymen FNAYOU - GitLab - GitHub
The MIT License (MIT). Please see License File for more information.