A library for easy creation of REST API clients.
First you need to add tenolo/apilyzer to composer.json:
Do it manually
{
"require": {
"tenolo/apilyzer": "~1.0"
}
}or just execute composer require tenolo/apilyzer.
Please note that dev-master latest development version.
Of course you can also use an explicit version number, e.g., 1.0.* or ^1.0.
As a second step you have to add HTTP-Client and a HTTP-Factory to your project in production or development environment.
You need one or more libraries that implements following packages:
- psr/http-message
- psr/http-client
- psr/http-factory-implementation
- php-http/client-implementation
This library intentionally does not provide packages so that each API client can implement its own.
We recommend the use of nyholm/psr7 and php-http/guzzle6-adapter.
For production use: composer require nyholm/psr7 php-http/guzzle6-adapter
For development use: composer require --dev nyholm/psr7 php-http/guzzle6-adapter
Create your own Gateway and Config class.
<?php
namespace App\Api\Gateway;
use Tenolo\Apilyzer\Gateway\Config as BaseConfig;
/**
* Class Config
*/
class Config extends BaseConfig
{
/**
* @inheritDoc
*/
public function getGatewayUrl(): string
{
return 'https://BASE.URL.TO.API.com/';
}
}<?php
namespace App\Api\Gateway;
use Tenolo\Apilyzer\Gateway\Gateway as BaseGateway;
use Tenolo\Apilyzer\Manager\EndpointManager;
use Tenolo\Apilyzer\Manager\EndpointManagerInterface;
/**
* Class Gateway
*/
class Gateway extends BaseGateway
{
/** @var EndpointManagerInterface */
protected $endpointManager;
/**
* @inheritDoc
*/
protected function getEndpointManager(): EndpointManagerInterface
{
if ($this->endpointManager === null) {
$this->endpointManager = $this->createEndpointManager();
}
return $this->endpointManager;
}
/**
* @return EndpointManagerInterface
*/
protected function createEndpointManager(): EndpointManagerInterface
{
return new EndpointManager(__DIR__.'/../Endpoint');
}
}