I'm trying to build an endpoint that forwards the data passed to it to an API using the Slim PHP Framework and I'm having trouble getting my response from a Guzzle request.
$app->map( '/api_call/:method', function( $method ) use( $app ){
$client = new GuzzleHttp\Client([
'base_url' => $app->config( 'api_base_url' ),
'defaults' => [
'query' => [ 'access_token' => 'foo' ],
]
]);
$request = $client->createRequest( $app->request->getMethod(), $method, [
'query' => $app->request->params()
]);
var_dump( $client->send( $request )->getBody() );
})->via( 'GET', 'POST', 'PUT', 'PATCH', 'DELETE' )->conditions( [ 'route' => '.+?' ] );`
This then gives me...
object(GuzzleHttp\Stream\Stream)[59]
private 'stream' => resource(72, stream)
private 'size' => null
private 'seekable' => boolean true
private 'readable' => boolean true
private 'writable' => boolean true
private 'meta' =>
array (size=6)
'wrapper_type' => string 'PHP' (length=3)
'stream_type' => string 'TEMP' (length=4)
'mode' => string 'w+b' (length=3)
'unread_bytes' => int 0
'seekable' => boolean true
'uri' => string 'php://temp' (length=10)
...instead of the response of 'cool' I was expecting.
If I just var_dump $client->sendRequest( $request )
I get a 200 OK, and the url is what I expect, http://localhost:8000/test?access_token=foo
.
I have another request, but only using $client->post(...)
and it works fine without giving me the stream thing back.
I've tried reading the stream using the example at the bottom (http://guzzle.readthedocs.org/en/latest/http-client/response.html) but it's telling me feof
doesn't exist.
Anyone have any idea what I'm missing or doing wrong here?