title: Learning how to access data from an API using Guzzle
body: <p>I'm building a new application that requires the use of an API, in particular one that uses OAuth, but to begin with I'm trying to just use a simple API to wrap my head around how to use one in an application as I've never used an API before.</p>
  
  <p>I'm running a fresh Laravel 5.1 project on my localhost with the <code>Guzzle</code> library installed.</p>
  
  <p>Following the instructions from the <a href="http://docs.guzzlephp.org/en/latest/" rel="nofollow">Guzzle documentation</a>, I believe I have set this up right, but I can't make heads or tales of the response I am getting.</p>
  
  <p>The API I am trying to use is <a href="http://freegeoip.net/" rel="nofollow">http://freegeoip.net/</a> and the format for making a request is <code>freegeoip.net/{format}/{IP_or_hostname}</code>.</p>
  
  <p>I've set up a page where I can type in an IP address and submit this, to which it is then run by the following function in my controller:</p>
  
  <pre><code>public function retrieve(Request $request)
      {
          $url = "http://freegeoip.net/json/" . $request-&gt;ipaddress;
          $client = new Client();
          $response = $client-&gt;request('GET', $url);
          dd($response);
      }
  </code></pre>
  
  <p>My routes and everything are set up correctly, and I am referencing Guzzle at the top of my controller with:</p>
  
  <pre><code>use GuzzleHttp\Client;
  </code></pre>
  
  <p>But the response I get from <code>dd($response);</code> doesn't make any sense to me or give any hints as to how I could get any information from it.</p>
  
  <p><strong>This is what the <code>dd($response)</code> outputs</strong></p>
  
  <pre><code>Response {#195 ▼
    -reasonPhrase: "OK"
    -statusCode: 200
    -headers: array:8 [▶]
    -headerLines: array:8 [▶]
    -protocol: "1.1"
    -stream: Stream {#186 ▶}
  }
  </code></pre>
  
  <p><strong>But when I run the equivalent URL through my browser I get</strong></p>
  
  <pre><code>{"ip":"202.21.xxx.xxx","country_code":"NZ","country_name":"New Zealand","region_code":"WGN","region_name":"Wellington","city":"Wellington","zip_code":"6011","time_zone":"Pacific/Auckland","latitude":-41.283,"longitude":174.784,"metro_code":0}
  </code></pre>
  
  <p>Can anyone help out with what I'm doing wrong or point to some good resources on how to get started using APIs with Laravel. There's a lot on how to build a Laravel API but not how to access one from Laravel.</p>