2013-10-31 15:25:29 -07:00
|
|
|
.. title:: Guzzle | PHP HTTP client and framework for consuming RESTful web services
|
2014-02-13 20:05:40 -08:00
|
|
|
|
|
|
|
======
|
|
|
|
Guzzle
|
|
|
|
======
|
|
|
|
|
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:53:47 -07:00
|
|
|
|
2015-03-21 19:30:11 -07:00
|
|
|
- Manages things like persistent connections, simplifies sending streaming
|
|
|
|
POST requests with fields and files, and abstracts away the underlying HTTP
|
|
|
|
transport layer.
|
|
|
|
- Can send both synchronous and asynchronous requests.
|
2014-10-12 18:27:08 -07:00
|
|
|
- Pluggable HTTP handlers allows Guzzle to integrate with any method you choose
|
2014-10-08 18:53:47 -07:00
|
|
|
for sending HTTP requests over the wire (e.g., cURL, sockets, PHP's stream
|
|
|
|
wrapper, non-blocking event loops like `React <http://reactphp.org/>`_, etc.).
|
|
|
|
- Guzzle makes it so that you no longer need to fool around with cURL options,
|
|
|
|
stream contexts, or sockets.
|
2015-03-21 19:30:11 -07:00
|
|
|
- Middleware system allows you to augment the behavior of a client.
|
2014-02-13 20:05:40 -08:00
|
|
|
|
|
|
|
.. code-block:: php
|
|
|
|
|
|
|
|
$client = new GuzzleHttp\Client();
|
2014-10-08 18:53:47 -07:00
|
|
|
$response = $client->get('http://guzzlephp.org');
|
|
|
|
$res = $client->get('https://api.github.com/user', ['auth' => ['user', 'pass']]);
|
|
|
|
echo $res->getStatusCode();
|
|
|
|
// "200"
|
|
|
|
echo $res->getHeader('content-type');
|
|
|
|
// 'application/json; charset=utf8'
|
|
|
|
echo $res->getBody();
|
|
|
|
// {"type":"User"...'
|
|
|
|
|
|
|
|
// Send an asynchronous request.
|
2015-03-21 19:30:11 -07:00
|
|
|
$promise = $client->getAsync('http://httpbin.org');
|
|
|
|
$promise->then(function ($response) {
|
|
|
|
echo 'I completed! ' . $response->getStatusCode();
|
2014-10-08 18:53:47 -07:00
|
|
|
});
|
2014-02-13 20:05:40 -08:00
|
|
|
|
2015-03-21 19:30:11 -07:00
|
|
|
|
2014-02-13 20:05:40 -08:00
|
|
|
User guide
|
|
|
|
----------
|
|
|
|
|
|
|
|
.. toctree::
|
|
|
|
:maxdepth: 2
|
|
|
|
|
|
|
|
overview
|
|
|
|
quickstart
|
|
|
|
clients
|
2015-03-21 19:30:11 -07:00
|
|
|
psr7
|
2015-03-28 15:33:35 -07:00
|
|
|
handlers-and-middleware
|
2014-03-24 21:10:05 -07:00
|
|
|
testing
|
2014-02-13 20:05:40 -08:00
|
|
|
faq
|