Reputation: 3521
I have this route
Route::get('/getLocation/{postalCode}', function () {
$response = Http::get('https://theapi');
return $response->json();
});
Sadly this doesn't work
I can reach the api with
https://theapi?PostalCode=xxxx
How can i replicate this in my route to work?
Upvotes: 0
Views: 119
Reputation: 4011
You got double }} there, try delete it so it will be like this:
Route::get('/getLocation/{postalCode}', function () {
$response = Http::get('https://theapi');
return $response->json();
});
Edit:
Add the route parameter to API function parameters
Route::get('/getLocation/{postalCode}', function ($postalCode) {
// do whatever you want to postalCode variable
$response = Http::get('https://theapi', [
'PostalCode' => $postalCode
]);
return $response->json();
});
Upvotes: 2