Guzzle: Guzzle Http strips off part of the base URL

Created on 1 Nov 2014  路  3Comments  路  Source: guzzle/guzzle

Does anyone know why Guzzle strips off /local/restful/web/app_dev.php part from the full base URL which is http://localhost/local/restful/web/app_dev.php? I have to give /local/restful/web/app_dev.php/api/v1/user.json in my Gherkin line to make the test pass which is a patchy solution and breaks other developers' tests.

Any workaround?

_My settings:_

Base URL: http://localhost/local/restful/web/app_dev.php
Api URL: http://localhost/local/restful/web/app_dev.php/api/v1/user.json

_ERROR_

When I send a "POST" request to "/api/v1/user.json"
  Client error response
  [status code] 404
  [reason phrase] Not Found
  [url] http://localhost/api/v1/user.json (Guzzle\Http\Exception\ClientErrorResponseException)

_Gherkin_

When I send a "POST" request to "/api/v1/user.json"

_FeatureContext_

class FeatureContext extends MinkContext implements KernelAwareContext
{
    public function __construct()
    {
        //Output is: http://localhost/local/restful/web/app_dev.php
        //echo $base_url;

        $this->client = new Client('http://localhost/local/restful/web/app_dev.php');
    }

    /**
     * @When /^I send a "([^"]*)" request to "([^"]*)"$/
     */
    public function iSendARequestTo($method, $uri)
    {
        $request = $this->client->createRequest($method, $uri);
        $this->response = $this->client->send($request);
    }
}

Most helpful comment

there are actually 2 things to consider:

  • your base url _should_ end in /
  • your relative url _should not_ start with /

All 3 comments

You need to use a relative path in order to merge it into the path of the base URL. So use api/v1/user.json instead of /api/v1/user.json. This pseudo-code shows how Guzzle combines relative URLs into a base URL: http://tools.ietf.org/html/rfc3986#section-5.2.2.

Excellent. That works.

there are actually 2 things to consider:

  • your base url _should_ end in /
  • your relative url _should not_ start with /
Was this page helpful?
0 / 5 - 0 ratings

Related issues

pionl picture pionl  路  4Comments

informagenie picture informagenie  路  3Comments

skovmand picture skovmand  路  5Comments

stof picture stof  路  5Comments

nimaamiri92 picture nimaamiri92  路  4Comments