Base_uri is not based on instantiating a guzzle client

I am using skylight trying to configure simple api requests via guzzle.

The problem is that the base_uri parameter does not display correctly on the initial new Client() .

A simplified example:

 use GuzzleHttp\Client; $client = new Client([ 'base_uri' => 'https://siteurl.com/api/v2' ]); 

Then call api via get

 $res = $client->get('orders', [ 'query' => [ 'status' => 'completed' ] ]); 

does not work. I tried not to use absolute URLs like /orders for example. If I get $client->get('https://siteurl.com/api/v2/orders') completely and just add it to the get $client->get('https://siteurl.com/api/v2/orders') method, it works.

I use: "laravel / lumen-framework": "5.0. *", "Guzzlehttp / guzzle": "^ 6.0"

* Subsequent:

I added a debug flag to compare the headers, and a noticeable difference is in the query string of the request.

The absolute URL of the get method (bypassing base_uri):

GET / api / v2 / orders? status = completed HTTP / 1.1

Using base_uri (version loses):

GET / api / orders? status = completed HTTP / 1.1

+8
lumen guzzle
source share
1 answer

You need to complete base_uri with a slash /

eg.

 use GuzzleHttp\Client; $client = new Client([ 'base_uri' => 'https://siteurl.com/api/v2/' ]); 

Edit: Note that base_uri is for Guzzle 6+, whereas previous versions used base_url.

+18
source share

All Articles