jeyroik/json-reqres

There is no license information available for the latest version (0.2.2) of this package.

Simple wrapper for json responses

0.2.2 2022-05-24 16:45 UTC

This package is auto-updated.

Last update: 2024-04-24 20:56:23 UTC


README

Simple wrapper for JSON responses.

tests codecov.io PHPStan Enabled 68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f63663034376361623533613830333066313462362f6d61696e7461696e6162696c697479 Latest Stable Version Total Downloads Dependents

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 with ApiKey dispatcher (see src\components\requests\dispatchers for details).