1
votes

Can anyone help me with my problem, i'm trying to use Guzzle in Laravel 5 and trying to retrieve a data from Rest API. i always get this when I dd().

Stream {#287-stream: :stream {@11 ▶}
  -size: null
  -seekable: true
  -readable: true
  -writable: true
  -uri: "php://temp"
  -customMetadata: []
}

and here's my controller, not sure if i'm integrating with guzzle properly.

<?php namespace App\Http\Controllers;

class SampleController extends \SleepingOwl\Admin\Controllers\AdminController {

    public function getIndex() {

        $client = new \GuzzleHttp\Client();
        $response = $client->get('http://httpbin.org/get');
        $body = $response->getBody();
        dd($body);
        //return \View::make('samplerest')->with('tests',$body);
    }
}
1
got it... turns out I just need to json_decode.David Alrdrin

1 Answers

1
votes

You can also use $response->json(); like this :

$client = new \GuzzleHttp\Client();
$response = $client->get('http://httpbin.org/get');
$json = $response->json();

Note that it'll throw an Exception if the response is not well formatted.