williamespindola / abstract-http-client
Abstract http client with guzzle
1.2.0
2017-12-05 01:29 UTC
Requires
- php: ~7.0
- guzzlehttp/guzzle: ~6.0
Requires (Dev)
- phpunit/phpunit: ^6.2
- squizlabs/php_codesniffer: ^2.3
This package is not auto-updated.
Last update: 2024-11-03 09:11:40 UTC
README
Abstract http client for:
- guzzle
Install
Via Composer
$ composer require williamespindola/abstract-http-client
Usage
extend
... use WilliamEspindola\AbstractHTTPClient\AbstractRequest; use GuzzleHttp\Psr7\Response; ... final class MyRequest extends AbstractRequest { /** * @var string $endPoint End point of resource */ protected $endPoint = '/some/end-point/:someStringParam'; public function request(string $someStringParam, int $someIntParam): Response { $this->setParameters([':someStringParam' => $someStringParam]); $this->httpClient->setOptions(['form_params' => ['someIntParam' => $someIntParam]]); return $this->httpClient->request('POST', $this->getURI()); } }
Instance
use GuzzleHttp\Client; use WilliamEspindola\AbstractHTTPClient\MyRequest; use WilliamEspindola\AbstractHTTPClient\Client\GuzzleClient; $instance = new MyRequest(new GuzzleClient(new Client), 'http://url');
Using extra query string
namespace WilliamEspindola\AbstractHTTPClient ... use WilliamEspindola\AbstractHTTPClient\Client\AbstractRequest; use WilliamEspindola\AbstractHTTPClient\Client\QueryString\ExtraQueryString; use GuzzleHttp\Psr7\Response; ... final class MyRequest extends AbstractRequest { use ExtraQueryString; /** * @var string $endPoint End point of resource */ protected $endPoint = '/some/end-point/:someStringParam'; public function request(string $someStringParam, int $someIntParam): Response { $this->setParameters([':someStringParam' => $someStringParam]); $this->httpClient->setOptions(['form_params' => ['someIntParam' => $someIntParam]]); return $this->httpClient ->request( 'POST', $this->getUriWithExtraString($this->getURI()) ); } }
Change log
Please see CHANGELOG for more information on what has changed recently.
Testing
$ composer test
Contributing
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
Security
If you discover any security related issues, please email oi@williamespindola.com.br instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.