Guzzle 6: no more json() method for responses
In Guzzle 6, the json()
method for parsing JSON responses has been removed. Instead, you can use the getBody()
method to retrieve the response body as a string and then use the json_decode() function in PHP to parse the JSON.
For example:
$response = $client->request('GET', 'https://jsonplaceholder.typicode.com/todos/1');
$data = json_decode($response->getBody(), true);
Watch a video course
Learn object oriented PHP
Additionally, you can use Guzzle's built-in stream
type to parse json responses.
$response = $client->request('GET', 'https://jsonplaceholder.typicode.com/todos/1');
$data = json_decode($response->getBody()->getContents());
This change was made to improve flexibility and allow for more fine-grained control over how responses are handled.