johnstones12
johnstones12

Reputation: 123

Laravel Guzzle GET request

    $client = new Client(['base_uri' => 'http://api.tvmaze.com/']);

    $res = $client->request('GET', '/schedule?country=US&date=2014-12-01');

    return $res;

returns this error:

"Class 'Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory' not found"

I've tried including "symfony/psr-http-message-bridge": "0.2", in my composer.json file

Upvotes: 11

Views: 12863

Answers (5)

KeitelDOG
KeitelDOG

Reputation: 5170

That's a bit old question. However, since the answers couldn't resolve it for me, here is a last thing to try when using Guzzle Http.

According to Laravel Documentation https://laravel.com/docs/5.3/requests#psr7-requests :

The PSR-7 standard specifies interfaces for HTTP messages, including requests and responses. If you would like to obtain an instance of a PSR-7 request instead of a Laravel request, you will first need to install a few libraries. Laravel uses the Symfony HTTP Message Bridge component to convert typical Laravel requests and responses into PSR-7 compatible implementations:

composer require symfony/psr-http-message-bridge
composer require zendframework/zend-diactoros

This solved my problem.

EDIT-------

As suggested in comments, the package zendframework/zend-diactoros is abandoned. Then it's better to use an alternate.

Suggested by Symfony PSR7 Bridge:

composer require nyholm/psr7

Or Laminas Diactoros Github Package:

composer require laminas/laminas-diactoros

Upvotes: 8

You need to get the body of the answer:

$client = new \GuzzleHttp\Client(['base_uri' => 'http://api.tvmaze.com/']);

$res = $client->request('GET', '/schedule?country=US&date=2014-12-01');

return $res->getBody();

Upvotes: 11

Rejneesh Raghunath
Rejneesh Raghunath

Reputation: 1724

You need to install the following additional symfony components with composer.

composer require symfony/psr-http-message-bridge
composer require nyholm/psr7

https://symfony.com/doc/..

Upvotes: 5

Leo
Leo

Reputation: 7420

Remove guzzle package first : composer remove guzzlehttp/guzzle

then do:

composer dump-autoload

finally re install it:

composer require guzzlehttp/guzzle

Also make sure you are using guzzle namespace:

use GuzzleHttp\Client;

Upvotes: 2

Richard-MX
Richard-MX

Reputation: 484

You are instantiating a Client but seems like you weren't explicit with the class being instantiated. Try this:

$client = new \GuzzleHttp\Client(['base_uri' => 'http://api.tvmaze.com/']);

$res = $client->request('GET', '/schedule?country=US&date=2014-12-01');

return $res;

Upvotes: 1

Related Questions