I am working on a project with a restful API. I use GuzzleHttp library in order to get/put etc. data in the API.
Is there any way where you can change GuzzleHttp\Client's base url on the run. My idea is because I have multiple endpoints of one api but the base url is not the same so I want to create one Client with some options but change the base url when I want to execute some request.
Up to version 5 of Guzzle, you can use setDefaultOption
method:
$client->setDefaultOption('base_uri', 'https://example.url');
As it is written in GuzzleHttp's documentation, if you pass absolute path to post/get/put, etc. it will override the current base url. So, if you prepend the absolute path it will get the job done. Check here, GuzzleHttp documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With