1
0
mirror of https://github.com/guzzle/guzzle.git synced 2025-01-17 21:38:16 +01:00
guzzle/README.md

89 lines
3.0 KiB
Markdown
Raw Normal View History

2015-03-28 15:36:00 -07:00
Guzzle, PHP HTTP client
=======================
2011-11-11 17:21:41 -06:00
2015-04-17 20:57:19 -07:00
[![Build Status](https://secure.travis-ci.org/guzzle/guzzle.svg?branch=master)](http://travis-ci.org/guzzle/guzzle)
2013-06-10 13:47:53 -07:00
2014-10-09 23:04:32 -07:00
Guzzle is a PHP HTTP client that makes it easy to send HTTP requests and
trivial to integrate with web services.
2014-10-08 18:35:23 -07:00
2015-03-29 11:10:33 -07:00
- Simple interface for building query strings, POST requests, streaming large
uploads, streaming large downloads, using HTTP cookies, uploading JSON data,
etc...
- Can send both synchronous and asynchronous requests using the same interface.
- Uses PSR-7 interfaces for requests, responses, and streams. This allows you
to utilize other PSR-7 compatible libraries with Guzzle.
- Abstracts away the underlying HTTP transport, allowing you to write
environment and transport agnostic code; i.e., no hard dependency on cURL,
PHP streams, sockets, or non-blocking event loops.
2015-03-29 12:34:54 -07:00
- Middleware system allows you to augment and compose client behavior.
2013-06-03 23:12:35 -07:00
```php
2014-03-02 10:45:13 -08:00
$client = new GuzzleHttp\Client();
$res = $client->get('https://api.github.com/user', ['auth' => ['user', 'pass']]);
2014-03-18 10:27:47 -07:00
echo $res->getStatusCode();
// "200"
2014-03-02 10:45:13 -08:00
echo $res->getHeader('content-type');
// 'application/json; charset=utf8'
echo $res->getBody();
// {"type":"User"...'
2014-10-08 18:35:23 -07:00
// Send an asynchronous request.
2015-03-28 15:36:00 -07:00
$request = new \GuzzleHttp\Psr7\Request('GET', 'http://httpbin.org');
$promise = $client->sendAsync($req)->then(function ($response) {
2014-10-08 18:35:23 -07:00
echo 'I completed! ' . $response;
});
2015-03-28 15:36:00 -07:00
$promise->wait();
2013-06-03 23:12:35 -07:00
```
2011-11-13 19:28:24 -06:00
2015-03-29 11:10:33 -07:00
## Help and docs
2014-03-02 10:45:13 -08:00
2015-03-29 11:10:33 -07:00
- [Documentation](http://guzzlephp.org/)
- [stackoverflow](http://stackoverflow.com/questions/tagged/guzzle)
- [Gitter](https://gitter.im/guzzle/guzzle)
2014-03-02 10:45:13 -08:00
2015-03-28 15:36:00 -07:00
2015-03-29 11:10:33 -07:00
## Installing Guzzle
2012-06-17 17:59:53 -07:00
2014-03-02 10:45:13 -08:00
The recommended way to install Guzzle is through
[Composer](http://getcomposer.org).
2012-06-17 17:59:53 -07:00
2013-06-03 23:12:35 -07:00
```bash
# Install Composer
curl -sS https://getcomposer.org/installer | php
2014-03-15 16:46:57 -07:00
```
Next, run the Composer command to install the latest stable version of Guzzle:
2012-06-17 17:59:53 -07:00
```bash
2015-03-02 13:11:30 -08:00
composer.phar require guzzlehttp/guzzle
2013-06-03 23:12:35 -07:00
```
2013-06-03 23:12:35 -07:00
After installing, you need to require Composer's autoloader:
2013-06-03 23:12:35 -07:00
```php
require 'vendor/autoload.php';
```
2015-03-29 11:10:33 -07:00
You can then later update Guzzle using composer:
2013-06-30 11:21:03 +01:00
2015-03-29 11:10:33 -07:00
```bash
composer.phar update
```
2015-05-26 11:22:06 -07:00
## Version Guidance
2015-05-26 20:17:25 -07:00
| Version | Status | Packagist | Repo | Docs | PSR-7 |
|---------|-------------|---------------------|---------------------|---------------------|-------|
| 3.x | EOL | `guzzle/guzzle` | [v3][guzzle-3-repo] | [v3][guzzle-3-docs] | No |
| 4.x | EOL | `guzzlehttp/guzzle` | N/A | N/A | No |
| 5.x | Maintained | `guzzlehttp/guzzle` | [v5][guzzle-5-repo] | [v5][guzzle-5-docs] | No |
| 6.x | Latest | `guzzlehttp/guzzle` | [v6][guzzle-6-repo] | [v6][guzzle-6-docs] | Yes |
[guzzle-3-repo]: https://github.com/guzzle3/guzzle
2015-05-26 20:21:48 -07:00
[guzzle-5-repo]: https://github.com/guzzle/guzzle/tree/5.3
2015-05-26 20:17:25 -07:00
[guzzle-6-repo]: https://github.com/guzzle/guzzle
2015-05-26 20:21:48 -07:00
[guzzle-3-docs]: http://guzzle3.readthedocs.org/en/latest/
[guzzle-5-docs]: http://guzzle.readthedocs.org/en/5.3/
[guzzle-6-docs]: http://guzzle.readthedocs.org/en/latest/