title: {guzzle-services} How to use middlewares with GuzzleClient client AS OPPOSED TO directly with raw GuzzleHttp\Client?
body: <p>My middleware need is to:</p>
  
  <ul>
  <li>add an extra query param to requests made by a REST API client derived from <code>GuzzleHttp\Command\Guzzle\GuzzleClient</code></li>
  </ul>
  
  <p>I cannot do this directly when invoking APIs through the client because <code>GuzzleClient</code> uses an API specification and it only passes on "legal" query parameters. Therefore I must install a middleware to intercept HTTP requests <strong>after</strong> the API client prepares them.</p>
  
  <p>The track I am currently on:</p>
  
  <ul>
  <li><code>$apiClient-&gt;getHandlerStack()-push($myMiddleware)</code></li>
  </ul>
  
  <p>The problem:</p>
  
  <p>I cannot figure out the RIGHT way to assemble the functional Russian doll that <code>$myMiddleware</code> must be. This is an <strong>insane</strong> gazilliardth-order function scenario, and the <strong>exact right</strong> way the function should be written seems to be <strong>different</strong> from the extensively documented way of doing things when working with <code>GuzzleHttp\Client</code> directly. No matter what I try, I end up having wrong things passed to some layer of the matryoshka, causing an argument type error, or I end up returning something wrong from a layer, causing a type error in Guzzle code.</p>
  
  <p>I made a carefully weighted decision to give up trying to understand. Please just give me a boilerplate solution <strong>for <code>GuzzleHttp\Command\Guzzle\GuzzleClient</code>, as opposed to <code>GuzzleHttp\Client</code></strong>.</p>