iammordaty / guzzle-json-response-middleware
简单的Guzzle 6.x JSON响应中间件
0.1
2019-10-18 19:19 UTC
Requires
- php: >=7.1
- ext-json: *
- guzzlehttp/promises: ^1.0
- guzzlehttp/psr7: ^1.6.1
This package is auto-updated.
Last update: 2024-09-29 06:02:39 UTC
README
简单的Guzzle 6.x JSON响应中间件。
安装
$ composer require iammordaty/guzzle-json-response-middleware
需求
- PHP 7.1
示例用法
use GuzzleHttp\Client; use GuzzleHttp\HandlerStack; use GuzzleJsonResponseMiddleware\JsonResponseMiddleware; $stack = HandlerStack::create(); $stack->push(new JsonResponseMiddleware(), JsonResponseMiddleware::NAME); $client = new Client([ 'handler' => $stack ]); $response = $client->get('http://www.mocky.io/v2/5db0b9312f00002901c13d8e'); // please note that the `getJson` method, excluding for the first one, accepts the same arguments // as native PHP's `json_decode` function $contents = $response->getBody()->getJson(true); print_r($contents); /* Outputs: Array ( [id] => 78349 [name] => John Smith [username] => @smith [email] => hello@smith.com [phone] => +1-202-555-0192 [website] => smith.dev ) */
许可证
iammordaty/guzzle-json-response-middleware遵循MIT许可证。