Multiple API call in blade I have got this in laravel HTTP client for using multiple API URL.
use Illuminate\Http\Client\Pool;
use Illuminate\Support\Facades\Http;
$responses = Http::pool(fn (Pool $pool) => [
$pool->get('http://localhost/first'),
$pool->get('http://localhost/second'),
$pool->get('http://localhost/third'),
]);
return $responses[0]->ok() &&
$responses[1]->ok() &&
$responses[2]->ok();
But how to use withHeaders for API host and API key. Then pass the data to the blade page...
Did you try just passing it to each?
$pool->get('http://localhost/first')->withHeaders($headers),
//or for all
$responses = Http::pool(fn (Pool $pool) => [
$pool->get('http://localhost/first'),
$pool->get('http://localhost/second'),
$pool->get('http://localhost/third'),
])->withHeaders($headers);
And passing to blade
return view('lala', compact('responses'));
@sinnbeck
$responses = Http::pool(fn (Pool $pool) => [
$pool->get('https://localhost/firsts'),
$pool->get('https://localhost/second'),
$pool->get('http://localhost/third'),
])->withHeaders([
'x-rapidapi-host' => $host,
'x-rapidapi-key' => $key
]);
It shows error
syntax error, unexpected '$pool' (T_VARIABLE), expecting ')'
@webfuelcode did your own first example work? It sounds like you are using an old php version
@Sinnbeck Ok I am using laravel 7 because I am still not good with the tailwind.
Is there any way to do so using laravel 7 or I have to use laravel 8...
@webfuelcode I am talking about php. But does your own original example work?
@Sinnbeck Using php 7
And the older examples are working
@webfuelcode 7.? 7.4 I assume. What line is throwing that error?
@Sinnbeck 7.3.2
Error in
$responses = Http::pool(fn (Pool $pool) => [
@webfuelcode the you cannot use short functions
$responses = Http::pool(function (Pool $pool) {
return [
$pool->get('https://localhost/firsts'),
$pool->get('https://localhost/second'),
$pool->get('http://localhost/third'),
];
})->withHeaders([
'x-rapidapi-host' => $host,
'x-rapidapi-key' => $key
]);
Please sign in or create an account to participate in this conversation.