Guide · Open source
How to use Guzzle: install it and send your first PHP HTTP request
Updated · written with AI from the project's own documentation and checked against our catalogue data
Guzzle is an open-source PHP HTTP client, released under the MIT licence, that lets a PHP program send HTTP requests to web APIs and websites. This guide is for PHP developers who want to call external services without writing low-level request code. By the end you will know how to install Guzzle with Composer, send a request, read the response, and find the documentation for more advanced features.
Quick start
- 1Check your PHP and Composer. Confirm you have PHP 7.4 or later and Composer installed. Check the version table in the README if you use an older PHP release.
- 2Install Guzzle. Run composer require guzzlehttp/guzzle in your project folder.
- 3Create a client. Create a new \GuzzleHttp\Client object in your PHP code.
- 4Send a request. Call the request method with an HTTP method such as GET and the URL you want to reach.
- 5Read the response. Use getStatusCode(), getHeaderLine() or getBody() to read the result.
- 6Explore the docs. Use the linked documentation pages for request options, middleware and exception handling.
What Guzzle does and when to use it
Guzzle lets a PHP program send HTTP requests, such as fetching data from a web API or posting data to one. It provides a single interface for query strings, POST requests, JSON bodies, cookies, and large uploads or downloads, so you do not have to write that request code yourself.
- Calling external REST or web service APIs from PHP
- Sending both synchronous and asynchronous requests through the same interface
- Keeping code independent of a specific transport such as cURL or PHP streams
- Extending request behaviour with middleware
Install Guzzle with Composer
The recommended way to install Guzzle is through Composer. You need PHP and Composer on your machine. Guzzle 8.3, the latest version listed in the README, requires PHP 7.4 or later, and older versions support a different range of PHP releases according to the version table in the README.
- Prerequisites: PHP 7.4 or later for version 8.3, and Composer
composer require guzzlehttp/guzzleSend your first request
Create a client object and call its request method with an HTTP method and a URL. The response object gives you the status code, headers, and body. The example below sends a GET request to a sample API address; replace it with the URL you need.
- getStatusCode() returns the HTTP status code
- getHeaderLine() returns a header value, such as content-type
- getBody() returns the response body
$client = new \GuzzleHttp\Client();
$response = $client->request('GET', 'https://api.example.com/users/123');
echo $response->getStatusCode(); // 200
echo $response->getHeaderLine('content-type'); // 'application/json'
echo $response->getBody(); // '{"id": 123, "name": "Ada"}'Where to find more examples and options
The README links to a set of documentation pages covering the Quick Start, request options, uploading data, cookies, exceptions, handlers, middleware and testing Guzzle clients. Start with the Quick Start for more examples, then read the request options page when you need to change how a request is sent.
- Quick Start and Overview
- Request Options and Uploading Data
- Cookies and Exceptions
- Handlers and Middleware
- Testing Guzzle Clients
Where to get help
The maintainers use GitHub issues only for bug reports and feature discussion. For usage questions, the README points to Stack Overflow under the guzzle tag, the #guzzle channel on the PHP-HTTP Slack, and Gitter. Security issues should be sent by email to the address listed in the README, not posted publicly.
What people use it for
- Fetching user data from a REST API into a PHP application
- Posting JSON data to a web service
- Uploading or downloading large files as streams
- Adding custom middleware to log or modify requests across a client
Frequently asked questions
Is Guzzle free to use?
Yes. Guzzle is made available under the MIT License, as stated in the README. The README also mentions a paid Tidelift Subscription for commercial support, which is optional.
What do I need to install Guzzle?
The README lists PHP 7.4 or later for version 8.3 and Composer as prerequisites. Install it with composer require guzzlehttp/guzzle.
Does Guzzle work with older PHP versions?
Support depends on the version table in the README. Older Guzzle releases support older PHP ranges, so check that table to choose a version that matches your PHP version.
Can I use Guzzle without writing code?
No. Guzzle is a PHP library, so it is meant for developers who write PHP. If you only need a browser-based tool or a command-line HTTP client without coding, Guzzle is not the right choice.
What are alternatives to Guzzle?
The source lists Symfony HttpClient, Requests for PHP, PHP cURL extension wrappers and Httpful as comparable projects. Compare them on the features you need, such as PSR support and asynchronous requests.
Where do I get help if something does not work?
The README suggests Stack Overflow under the guzzle tag, the #guzzle channel on the PHP-HTTP Slack, or Gitter. GitHub issues are for bugs and new features only.
New agent skills, repos and AI tools — every week
The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.
Our verdict
Guzzle suits PHP developers who need to call REST or web service APIs and want synchronous and asynchronous requests through one interface, with middleware for customisation. If your project is not PHP, or you only need a no-code HTTP tool, pick a different option such as a command-line client or a browser-based tool.
Install options & downloads