semperton / proxy
Simple PHP proxy.
0.2.1
2021-06-12 10:11 UTC
Requires
- php: >=7.1
- psr/http-client: ^1.0
- psr/http-message: ^1.0
Requires (Dev)
- httpsoft/http-message: ^1.0
- phpunit/phpunit: ^9.5
- vimeo/psalm: ^4.7
README
Semperton Proxy
Simple PSR-18 HTTP client based on PHP's native stream socket.
Installation
Just use Composer:
composer require semperton/proxy
Proxy requires PHP 7.1+
Usage
The client does not come with a PSR-17 request/response factory by itself. You have to provide one in the constructor.
use HttpSoft\Message\ResponseFactory; use Semperton\Proxy\Client; $client new Client( new ResponseFactory(), // any PSR-17 compilant response factory 5, // request timeout in secs $options, // array of stream context options 4096 // buffer size used to read/write request body );
The client exposes only one public method sendRequest
:
use HttpSoft\Message\RequestFactory; use Psr\Http\Message\ResponseInterface; $requestFactory = new RequestFactory(); $request = $requestFactory->createRequest('GET', 'https://google.com'); $response = $client->sendRequest($request); $response instanceof ResponseInterface // true
Note
This is just a very simple HTTP client for single requests. If you are going to do heavy API work (multiple asynchronous requests, body parsing, etc.), you should consider using guzzlehttp/guzzle
or symfony/http-client
.