middlewares / proxy
Middleware to forward requests and return responses
Installs: 3 912
Dependents: 1
Suggesters: 0
Security: 0
Stars: 22
Watchers: 2
Forks: 6
Open Issues: 0
Requires
- php: ^7.2 || ^8.0
- guzzlehttp/guzzle: ^6.2
- psr/http-server-middleware: ^1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.0
- laminas/laminas-diactoros: ^2.3
- middlewares/utils: ^3.0
- oscarotero/php-cs-fixer-config: ^1.0
- phpstan/phpstan: ^0.12
- phpunit/phpunit: ^8|^9
- squizlabs/php_codesniffer: ^3.0
README
Middleware to create a http proxy using Guzzle.
Requirements
- PHP >= 7.2
- A PSR-7 http library
- A PSR-15 middleware dispatcher
Installation
This package is installable and autoloadable via Composer as middlewares/proxy.
composer require middlewares/proxy
Example
$target = new Uri('http://api.example.com'); $dispatcher = new Dispatcher([ new Middlewares\Proxy($target) ]); $response = $dispatcher->dispatch(new ServerRequest());
Usage
You need a Psr\Http\Message\UriInterface
with the target of the proxy.
use Middlewares\Utils\Dispatcher; use Middlewares\Utils\Factory; $target = Factory::createUri('http://api.example.com'); Dispatcher::run([ new Middlewares\Proxy($target) ]);
client
Instance of the client used to execute the requests. If it's not provided, an instance of GuzzleHttp\Client
is created automatically.
$target = Factory::createUri('http://api.example.com'); $client = new Client(); $proxy = (new Middlewares\Proxy($target))->client($client);
options
Options passed to the guzzle client. See the guzzle documentation for more information
Please see CHANGELOG for more information about recent changes and CONTRIBUTING for contributing details.
The MIT License (MIT). Please see LICENSE for more information.