Using Guzzle with Laravel Example

Guzzle is a PHP HTTP client that makes it easy to send HTTP requests and simple to integrate with web services. In this article, we will use Guzzle with Laravel. With guzzle, we will send HTTP request to a server and get HTTP response. It is alternate to CURL which provide more features along with easy user interface. Different methods you can send with Guzzle are GET, DELETE, HEAD, PATCH, POST and PUT.

Install Guzzle

You can install Guzzle using composer:

Configure Route

Let’s define example route for sending a request to server.

Create Controller

By running the following command inside of your project folder, create a new controller to test our Guzzle integration on Laravel application.

Using Guzzle in Controller

Now, let’s open our newly created controller and make some changes. I have commented each line to help you understand the code.

Post Request using Guzzle

Put Request using Guzzle

Delete Request using Guzzle

Async Requests

You can send asynchronous request using Guzzle.

Concurrent Request

You can also send Concurrent Request using promises and asynchronous requests.

You can find more examples and documentation in detail at this guzzle official documentation.

Leave a Reply

Your email address will not be published. Required fields are marked *