index.rst 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. .. title:: Guzzle, PHP HTTP client
  2. ====================
  3. Guzzle Documentation
  4. ====================
  5. Guzzle is a PHP HTTP client that makes it easy to send HTTP requests and
  6. trivial to integrate with web services.
  7. - Simple interface for building query strings, POST requests, streaming large
  8. uploads, streaming large downloads, using HTTP cookies, uploading JSON data,
  9. etc...
  10. - Can send both synchronous and asynchronous requests using the same interface.
  11. - Uses PSR-7 interfaces for requests, responses, and streams. This allows you
  12. to utilize other PSR-7 compatible libraries with Guzzle.
  13. - Abstracts away the underlying HTTP transport, allowing you to write
  14. environment and transport agnostic code; i.e., no hard dependency on cURL,
  15. PHP streams, sockets, or non-blocking event loops.
  16. - Middleware system allows you to augment and compose client behavior.
  17. .. code-block:: php
  18. $client = new GuzzleHttp\Client();
  19. $res = $client->request('GET', 'https://api.github.com/user', [
  20. 'auth' => ['user', 'pass']
  21. ]);
  22. echo $res->getStatusCode();
  23. // "200"
  24. echo $res->getHeader('content-type')[0];
  25. // 'application/json; charset=utf8'
  26. echo $res->getBody();
  27. // {"type":"User"...'
  28. // Send an asynchronous request.
  29. $request = new \GuzzleHttp\Psr7\Request('GET', 'http://httpbin.org');
  30. $promise = $client->sendAsync($request)->then(function ($response) {
  31. echo 'I completed! ' . $response->getBody();
  32. });
  33. $promise->wait();
  34. User Guide
  35. ==========
  36. .. toctree::
  37. :maxdepth: 3
  38. overview
  39. quickstart
  40. request-options
  41. psr7
  42. handlers-and-middleware
  43. testing
  44. faq