I use Guzzle in the PHPUnit test suite for the REST API.
I create my client as follows:
use GuzzleHttp\Client; $client = new Client(['base_url' => ['http://api.localhost/api/{version}', ['version' => '1.0']]]);
This works fine, and I can make requests using the following code:
$request = $client->createRequest('GET', '/auth'); $request->setBody(Stream::factory(json_encode(['test'=>'data']))); $response = $client->send($request); $decodedResponse = $response->json();
However, Guzzle ignores the /api/{version} base URL and makes the request here:
http://api.localhost/auth
However, I would expect it to make a request here:
http://api.localhost/api/1.0/auth
Have I really read the documentation wrong, and I suppose this is a wrong behavior, or is there some other parameter, do I need to enable it to add /auth url to it to the base path /api/1.0 when executing the request?
php guzzle
Benjamin nolan
source share