Reputation: 97
I am not able to use URI templating in Guzzle 6.
My code(Updated):
self::$client = new Client(["base_uri" => "http://example.com/api/", "cookies" => true]);
$result = self::$client->get(["project/{projectId}", ["projectId" => $projectId]]);
I've checked this old documentation and this question but can't make it work.
Exception thrown is: URI must be a string or UriInterface.
I can't find any documentation related to this for Guzzle 6.
Upvotes: 1
Views: 223
Reputation: 5324
Guzzle's get
method definition is get(string|UriInterface $uri, array $options = [])
and you are passing array as $uri
which is not allowed here.
You have to build uri yourself, since guzzle does not do that for you.
Correct chunk of code should look like this (if projectId
is an integer):
$result = self::$client->get(sprintf('project/%d', $projectId));
Upvotes: 1