jeyroik / json-reqres
此包最新版本(0.2.2)没有提供许可证信息。
JSON响应的简单封装器
0.2.2
2022-05-24 16:45 UTC
Requires
Requires (Dev)
- phpstan/phpstan: 0.*
- phpunit/phpunit: ^9
README
JSON响应的简单封装器。
使用方法
$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);
分发器
您还可以通过分发器逻辑来分发请求
$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' ] ]);
- 请求分发器应实现
jeyroik\interfaces\requests\dispatchers\IDispatcher
接口。 - 响应分发器应实现
jeyroik\interfaces\responses\dispatchers\IDispatcher
接口。 - 默认请求分发器是
jeyroik\components\requests\dispatchers\ApiKey
。请参阅此类以获取使用细节。 - 默认响应分发器是
jeyroik\components\responses\dispatchers\WrapResult
。请参阅此类以获取使用细节。
环境
以下环境参数可用
REQRES__CLIENT
客户端类名,例如\\GuzzleHttp\\Client
。REQRES__API_KEY__TOKEN
用于与ApiKey
分发器一起使用的API密钥令牌(有关详细信息,请参阅src\components\requests\dispatchers
)。