title: Laravel 5 API using json and Guzzle
body: <p>I'm quite new to Laravel 5 but I'm working on project involing 2 servers (S1 and S2). Each one is running a Laravel 5 REST WebService (API) WS1 and WS2.</p>
  
  <p>The workflow is the following : </p>
  
  <ol>
  <li>WS1 : just get a query like <a href="http://s1.ip/api/object/1" rel="nofollow noreferrer">http://s1.ip/api/object/1</a> where 1 is the id of the object. It just "reroute" the query to WS2.</li>
  <li>WS2 : get the same kind of query <a href="http://s2.ip/api/object/1" rel="nofollow noreferrer">http://s2.ip/api/object/1</a> using a personnal access token from Laravel/Passport.</li>
  <li>WS2 : Ask the local mysql DB to know if the object with id 1 is 'valid' or not.</li>
  <li>WS2 : Create a response to the WS1 Query using json. Something like :
  {"id": "2", "valid": true}</li>
  <li>WS1 : get the response from WS2 and from it create its own response to the initial GET query.</li>
  </ol>
  
  <p>I test my REST API using Postman.</p>
  
  <p>WS2 is work well when using Postman.</p>
  
  <p>But when I try to query WS1, I never get the json from the response that is send from WS2.</p>
  
  <p>Hope I clear.</p>
  
  <p>Here are some of my source code:</p>
  
  <p><strong>routes\api.php</strong></p>
  
  <pre><code>Route::get('/object/{obj_id?}', 'ObjectController@check')-&gt;where('obj_id', '[0-9]+');
  </code></pre>
  
  <p><strong>app\Http\Controllers\ObjectController.php</strong></p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers;
  
  use Illuminate\Http\Request;
  use Illuminate\Http\Response;
  
  use GuzzleHttp\Exception\GuzzleException;
  use GuzzleHttp\Client;
  
  use App\Http\Requests;
  use App\Http\Controllers\Controller;
  
  class ObjectController extends Controller
  {
      public function check($obj_id)
      {
          $token = 'my personnal access tokens from WS2 Laravel/Passport'
          $client = new Client();
          $body = $client-&gt;request('GET','http://S2.ip/api/object/' . $object_id, [
              'Accept' =&gt; 'application/json',
              'Content-Type' =&gt; 'application/json',
              'Authorization' =&gt; 'bearer ' . $token, 
          ])-&gt;getBody();
  
      $contents = (string) $body;
      $data = json_decode($contents);
      dd($data); // to see what's inside $data
  </code></pre>
  
  <p>The dd($data) output the following : <strong>null</strong></p>
  
  <p>I have try many things but I never manager to get the json.
  What am I doing wrong. I would really appreciate some help on this.</p>
  
  <p>Thanks</p>
  
  <p>Edit: </p>
  
  <p>Here is the S2 answer I got from PostMan or Rested:</p>
  
  <p>S2 returns the following when using Postman:</p>
  
  <pre><code>Response - http://s2.ip/api/object/1
  
  200 OK
  Headers 
  
  Date: Thu, 12 Jan 2017 08:38:31 GMT
  Vary: Authorization
  Server: Apache/2.4.17 (Win32) OpenSSL/1.0.2d PHP/5.6.21
  X-Powered-By: PHP/5.6.21
  X-RateLimit-Remaining: 59
  Content-Type: application/json
  Cache-Control: no-cache
  X-RateLimit-Limit: 60
  Connection: Keep-Alive
  Keep-Alive: timeout=5, max=100
  Content-Length: 46
  Response body 
  
  {
      "id": "1",
      "authorized": false
  }
  </code></pre>