I want to send HTTP requests from Laravel to an external website. Specifically, I need to retrieve an object from an API using an HTTP request, similar to jQuery’s AJAX. In WordPress, I used to use the wp_remote_request()
function for similar tasks. What are my options in Laravel?
You can try Guzzle HTTP client package to send HTTP requests. Here’s how you can utilize it:
$client = new \GuzzleHttp\Client();
$response = $client->request('GET', 'https://api.example.com/data');
echo $response->getStatusCode(); // "200"
echo $response->getBody()->getContents();
With \GuzzleHttp\Client()
, you can send HTTP requests in Laravel, similar to how you would use wp_remote_request()
in WordPress.