8p / EightPointsGuzzleBundle

⛽️ Integrates Guzzle 6.x, a PHP HTTP Client, into Symfony
MIT License
440 stars 71 forks source link

Allowing optional version over base url #139

Closed pc-magas closed 7 years ago

pc-magas commented 7 years ago

During the Bundle usage I have the following url in order to use for my api http://example.com/v1/. But if I set the following config:

guzzle:
  clients:
    api_example:
       base_url: "http://example.com/v1/"

And then I use the following code:

class ApiCall {

  public function __construct( Client $urlFetcher, ) {
      $this->urlFetcher=$urlFetcher;
      $this->apiCallUrl='/example';
  }

  public function callApi(){
    $result=$this->urlFetcher->request('GET',$url,[ "query" => $urlParams ]);
  }
}

Then when I try to call the callApi of the class above I get an exception with the following error message:

Client error: GET http://example.com/example resulted in a 405 Method Not Allowed response: {"name":"MethodNotAllowed","message":"Wrong api Call"}

AThat means that the base_url ignores the /v1/ part of the base url. Wouldn't be a good idea to somehow include it when I perform the api call or tell to use the full url?

gregurco commented 7 years ago

@pc-magas it's normal behaviour. Please read this article: http://docs.guzzlephp.org/en/stable/quickstart.html#creating-a-client There are some examples and references to standards that should be respected.