jeyroik / json-reqres
Simple wrapper for json responses
Installs: 8
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/jeyroik/json-reqres
Requires
Requires (Dev)
- phpstan/phpstan: 0.*
- phpunit/phpunit: ^9
README
Simple wrapper for JSON responses.
Usage
$request = new Request([ Request::FIELD__METHOD => Request::METHOD__GET, Request::FIELD__BASE_URL => 'https://github.com/', Request::FIELD__ENDPOINT => 'operationName', Request::FIELD__PARAMETERS => [ 'param1' => 'value1' ] ]); $response = $request->run(); print_r($response->getResult(), true);
Dispatchers
You can additionally dispatch request by dispatcher logic:
$request = new Request([ Request::FIELD__METHOD => Request::METHOD__GET, Request::FIELD__BASE_URL => 'https://github.com/', Request::FIELD__ENDPOINT => 'operationName', Request::FIELD__DISPATCHER_REQUEST => '\\dispatcher\\class\\Name', Request::FIELD__DISPATCHER_RESPONSE => '\\dispatcher\\class\\Name', Request::FIELD__PARAMETERS => [ 'param1' => 'value1' ] ]);
- Request dispatcher should implement
jeyroik\interfaces\requests\dispatchers\IDispatcher
interface. - Response dispatcher should implement
jeyroik\interfaces\responses\dispatchers\IDispatcher
interface. - Default request dispatcher is
jeyroik\components\requests\dispatchers\ApiKey
. See this class for usage details. - Default response dispatcher is
jeyroik\components\responses\dispatchers\WrapResult
. See this class for usage details.
Environment
This env parameters are available:
REQRES__CLIENT
client class name, for example\\GuzzleHttp\\Client
.REQRES__API_KEY__TOKEN
api key token for using withApiKey
dispatcher (seesrc\components\requests\dispatchers
for details).