Guzzle in Drupal 8 and as a REST client - Артем Мирошник

968 views

Published on

Забудьте о drupal_http_request, pure curl, file_get_contents либо подобные устаревшие подходы!
http://docs.guzzlephp.org/ - фреймворк для работы с HTTP запросами, удобный способ создавать REST web service клиенты, просто отличная абстракция над curl.

Published in: Internet, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
968
On SlideShare
0
From Embeds
0
Number of Embeds
135
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Guzzle in Drupal 8 and as a REST client - Артем Мирошник

  1. 1. Guzzle in Drupal 8 and as Rest Client
  2. 2. Guzzle in Drupal 8 and as Rest Client Artem Miroshnyk Propeople
  3. 3. Guzzle is a PHP HTTP client that makes it easy to work with HTTP/1. 1 and takes the pain out of consuming web services. http://guzzlephp.org
  4. 4. Features: ● Pluggable HTTP adapters that can send requests serially or in parallel ● Streams data for both uploads and downloads ● Provides event hooks & plugins for cookies, caching, logging, OAuth, mocks, etc… ● Keep-Alive & connection pooling ● SSL Verification ● Automatic decompression of response bodies ● Streaming multipart file uploads ● Connection timeouts
  5. 5. Requirements (according to the packegist): 1. ext-curl: * 2. php: >=5.3.3 3. symfony/event-dispatcher: ~2.1 4. phpunit/phpunit: 3.7.* 5. doctrine/cache: ~1.3 6. symfony/class-loader: ~2.1 7. monolog/monolog: ~1.0 8. psr/log: ~1.0 9. zendframework/zend-cache: 2.*,<2.3 10. zendframework/zend-log: 2.*,<2.3
  6. 6. Build-in plugins ● Async. Allows to make “ping” requests which does not wait for the response. ● Backoff. Automatically retries to send response after fail using several stategies. ● Cache. HTTP Cache Plugin that caches reponses using HTTP spec. ● Cookie. Adds, extracts, and persists cookies between HTTP requests. ● CurlAuth. DEPRECATED ● ErrorResponse. Allows to throw generic exception using full response data. ● History. Stores all requests and responses in the memory. ● Log. Adapter between HTTP Client and loggers. ● Md5. Adds ContentMD5 header and MD5 validations to responses. ● Mock. Creates queue of client responses that is useful for testing and offline development. ● OAuth. Just OAuth ;)
  7. 7. Example (was stolen from off site)
  8. 8. Service description
  9. 9. Service description usage Or you can add service description via additional factor method as well as attach plugin.
  10. 10. drupal_http_request() RIP Drupal::httpClient() - welcome! Usage:
  11. 11. Lets use our service description! Run: composer require guzzlehttp/guzzle-service 0.2 TBD

×