2015-04-02 00:52:21 -07:00
|
|
|
.. title:: Guzzle, PHP HTTP client
|
2014-02-13 20:05:40 -08:00
|
|
|
|
2015-04-02 00:52:21 -07:00
|
|
|
====================
|
|
|
|
Guzzle Documentation
|
|
|
|
====================
|
2014-02-13 20:05:40 -08: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:53:47 -07:00
|
|
|
|
2015-03-29 12:34:54 -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.
|
|
|
|
- Middleware system allows you to augment and compose client behavior.
|
2014-02-13 20:05:40 -08:00
|
|
|
|
|
|
|
.. code-block:: php
|
|
|
|
|
|
|
|
$client = new GuzzleHttp\Client();
|
2015-09-06 11:18:04 -07:00
|
|
|
$res = $client->request('GET', 'https://api.github.com/user', [
|
|
|
|
'auth' => ['user', 'pass']
|
|
|
|
]);
|
2014-10-08 18:53:47 -07:00
|
|
|
echo $res->getStatusCode();
|
|
|
|
// "200"
|
2017-12-08 15:56:13 -05:00
|
|
|
echo $res->getHeader('content-type')[0];
|
2014-10-08 18:53:47 -07:00
|
|
|
// 'application/json; charset=utf8'
|
|
|
|
echo $res->getBody();
|
|
|
|
// {"type":"User"...'
|
|
|
|
|
|
|
|
// Send an asynchronous request.
|
2015-03-29 12:34:54 -07:00
|
|
|
$request = new \GuzzleHttp\Psr7\Request('GET', 'http://httpbin.org');
|
2015-05-27 15:43:11 +01:00
|
|
|
$promise = $client->sendAsync($request)->then(function ($response) {
|
2015-06-30 09:15:07 -07:00
|
|
|
echo 'I completed! ' . $response->getBody();
|
2014-10-08 18:53:47 -07:00
|
|
|
});
|
2015-03-29 12:34:54 -07:00
|
|
|
$promise->wait();
|
2014-02-13 20:05:40 -08:00
|
|
|
|
2015-03-21 19:30:11 -07:00
|
|
|
|
2015-04-02 00:52:21 -07:00
|
|
|
User Guide
|
|
|
|
==========
|
2014-02-13 20:05:40 -08:00
|
|
|
|
|
|
|
.. toctree::
|
2015-04-02 00:52:21 -07:00
|
|
|
:maxdepth: 3
|
2014-02-13 20:05:40 -08:00
|
|
|
|
|
|
|
overview
|
|
|
|
quickstart
|
2015-03-29 12:41:58 -07:00
|
|
|
request-options
|
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
|