GuzzleHttp \ Client changes base url dynamically

I am working on a project with the rest of the API. I use the GuzzleHttp library to get / place data in the API.

Is there a way in which you can change the URL of GuzzleHttp \ Client in a run. My idea is that I have several endpoints of the same api, but the base url is not the same, so I want to create one Client with some parameters, but change the base url when I want to execute some request .

+7
rest php guzzle
source share
2 answers

As written in the GuzzleHttp documentation, if you go the absolute path to post / get / put, etc., it will override the current base url. So, if you add an absolute path, it will do its job. Check here for GuzzleHttp documentation

+6
source
$client->setDefaultOption('base_uri', 'https://example.url'); 
+2
source

All Articles