tenolo / apilyzer
A library for easy creation of REST API clients
Requires
- php: ^7.2
- ext-json: *
- jms/serializer: ^1.9
- nesbot/carbon: ^2.18
- php-http/client-common: ^1.7|^2.0
- php-http/client-implementation: ^1.0
- php-http/discovery: ^1.6
- php-http/logger-plugin: ^1.0
- php-http/promise: ^1.0
- php-http/stopwatch-plugin: ^1.1
- psr/http-client: ^1.0
- psr/http-factory-implementation: ^1.0
- psr/http-message: ^1.0
- psr/log: ^1.1
- ramsey/collection: ^1.0
- symfony/event-dispatcher: ^2.8|^3.4|^4.0
- symfony/filesystem: ^2.8|~3.4|~4.0
- symfony/finder: ^2.8|~3.4|~4.0
- symfony/options-resolver: ^2.8|~3.4|~4.0
- symfony/routing: ^2.8|~3.4|~4.0
- symfony/stopwatch: ^2.8|~3.4|~4.0
- symfony/var-dumper: ^2.8|^3.4|^4.0
- tenolo/utilities: ^1.7
Requires (Dev)
- nyholm/psr7: ^1.0
- php-http/guzzle6-adapter: ^2.0
- phpunit/phpunit: ^8.1
- squizlabs/php_codesniffer: ^3.4
This package is auto-updated.
Last update: 2024-10-29 05:16:56 UTC
README
Apilyzer
A library for easy creation of REST API clients.
Install instructions
Composer
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
.
HTTP Client and Factory
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
Usage
First Steps
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'); } }