Reputation: 45
I'm trying to make an API request between two laravel websites. For the first website, this is how it's structured.
api.php
use Illuminate\Support\Facades\Route;
Route::group(['prefix' => 'v1'], function () {
Route::get('getCountries', 'ApiController@getCountries');
});
ApiController
public function getCountries()
{
$country = Country::get();
$country->makeHidden(['flag']); //svg
return $country;
}
This returns on postman using GET https://website.com/api/v1/getCountries:
[{"id":1,"iso":"AF","name":"AFGHANISTAN","nicename":"Afghanistan","iso3":"AFG","numcode":4,"phonecode":93,"created_at":null,"updated_at":null},{"id":2,"iso":"AL","name":"ALBANIA","nicename":"Albania","iso3":"ALB","numcode":8,"phonecode":355,"created_at":null,"updated_at":null},{"id":3,"iso":"DZ","name":"ALGERIA","nicename":"Algeria","iso3":"DZA","numcode":12,"phonecode":213,"created_at":null,"updated_at":null},{"id":4,"iso":"AS","name":"AMERICAN SAMOA","nicename":"American Samoa","iso3":"ASM","numcode":16,"phonecode":1684,"created_at":null,"updated_at":null},{"id":5,"iso":"AD","name":"ANDORRA","nicename":"
On a different website, calling this API endpoint with this
web.php
use Illuminate\Support\Facades\Http;
Route::get('/test', function () {
$response = Http::get('http://website.com/api/v1/getCountries');
dd($response);
});
gives cURL error 28: Failed to connect to website.com port 80: Connection timed out.
Any idea as how to make an API call between 2 laravel websites? Could it be something related to Auth, Headers or something else?
Upvotes: 0
Views: 482
Reputation: 45
This issue was simply a firewall configuration on the server that didn't allow requests to come from the same place. Hosting opened up the required port and it worked without any issues.
Upvotes: 1