guzzlehttp/guzzle
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
guzzlehttp/promises | 2.0.1 | 25.28 kB | MIT | prod | |
guzzlehttp/psr7 | 2.6.1 | 76.22 kB | MIT | prod | |
psr/http-client | 1.0.3 | - | MIT | prod | |
symfony/deprecation-contracts | v3.4.0 | - | MIT | prod |
Guzzlehttp/guzzle is a robust PHP HTTP client that facilitates sending HTTP requests and makes it seamless to integrate with web services. It offers a straightforward interface for tasks like building query strings, POST requests, streaming large uploads, downloads, cookies, and JSON data uploading, among others. It supports both synchronous and asynchronous requests using the same interface, and it is built around PSR-7 interfaces for requests, responses, and streams, leading to high interoperability with other libraries meeting the same PSR standard.
To utilize Guzzlehttp/guzzle in your projects, the recommended installation method is via Composer, a PHP dependency manager. You can command it to install Guzzle with the following terminal command: composer require guzzlehttp/guzzle
.
After the package is installed, you can then employ it in your PHP scripts as follows:
$client = new \GuzzleHttp\Client();
$response = $client->request('GET', 'https://api.github.com/repos/guzzle/guzzle');
echo $response->getStatusCode(); // Outputs: 200
echo $response->getHeaderLine('content-type'); // Outputs: 'application/json; charset=utf8'
echo $response->getBody(); // Outputs the body content received from the response.
//You can also send an asynchronous request.
$request = new \GuzzleHttp\Psr7\Request('GET', 'http://httpbin.org');
$promise = $client->sendAsync($request)->then(function ($response) {
echo 'I completed! ' . $response->getBody();
});
$promise->wait();
This example initializes a client, sends a GET request to a specified URL, and retrieves the response's status code, header, and body. Asynchronously sending a request is also illustrated.
The Guzzlehttp/guzzle's detailed documentation can be accessed at the following URL: https://docs.guzzlephp.org. In addition to the official documentation, you can also reach out to the Guzzle community on Stack Overflow or the dedicated Guzzle channels on Slack and Gitter for further assistance or to discuss specific topics.