title: Creating a common REST API consumption module for Zend Framework 2
body: <p>All,</p>
  
  <p>I am looking for some pointers to create a common module for 10 of my PHP applications to use. All these 10 applications will need to consume third party rest apis. They don't need to create APIs, just consume only.</p>
  
  <p>So, I have this code to consume a rest api. How do I go about creating a common REST API consumption module from this code, so I don't need to duplicate this code across all my php applications?</p>
  
  <pre><code>use Zend\Http\Request;
  use Zend\Http\Client;
  use Zend\Stdlib\Parameters;
  
  $request = new Request();
  $request-&gt;getHeaders()-&gt;addHeaders(array(
      'Content-Type' = &gt; 'application/x-www-form-urlencoded; charset=UTF-8'
  ));
  $request-&gt;setUri($someurl);
  $request-&gt;setMethod('POST');
  $request-&gt;setPost(new Parameters(array('someparam' = &gt; $somevalue)));
  
  $client = new Client();
  $response = $client-&gt;dispatch($request);
  $data = json_decode($response-&gt;getBody(), true);
  </code></pre>