11
Guzzle in Drupal 8 and as Rest Client

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

Embed Size (px)

DESCRIPTION

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

Citation preview

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

Guzzle in Drupal 8 and as Rest Client

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

Guzzle in Drupal 8 and as Rest ClientArtem Miroshnyk

Propeople

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

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

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

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

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

Requirements (according to the packegist):1. ext-curl: *2. php: >=5.3.33. symfony/event-dispatcher: ~2.14. phpunit/phpunit: 3.7.*5. doctrine/cache: ~1.36. symfony/class-loader: ~2.17. monolog/monolog: ~1.08. psr/log: ~1.09. zendframework/zend-cache: 2.*,<2.3

10. zendframework/zend-log: 2.*,<2.3

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

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 ;)

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

Example (was stolen from off site)

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

Service description

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

Service description usage

Or you can add service description via additional factor method as well as attach plugin.

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

drupal_http_request() RIP\Drupal::httpClient() - welcome!

Usage:

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

Lets use our service description!

Run:composer require guzzlehttp/guzzle-service 0.2

TBD