Upgrade to Pro — share decks privately, control downloads, hide ads and more …

psr-7-packages

 psr-7-packages

A talk about packages that use the common request/response interfaces of PSR-7. They showcase the force of interoperable interfaces.

Demo code for this talk can be found here: https://github.com/hannesvdvreken/psr7-demo

Presented at php.gent for the first time on June 30th 2015.

Hannes Van De Vreken

June 30, 2015
Tweet

More Decks by Hannes Van De Vreken

Other Decks in Technology

Transcript

  1. GUZZLEHTTP/GUZZLE - MIDDLEWARES $stack = HandlerStack::create(); $client = new Client(['handler'

    => $stack]); $stack->push($middleware); $stack->unshift($middleware);
  2. GUZZLEHTTP/GUZZLE - MIDDLEWARES $middleware = function ($handler) { return function

    ($request, $options) use ($handler) { // Do before return $handler($request, $options) ->then(function () { // Do after }); }; }
  3. GUZZLEHTTP/GUZZLE - PROGRESS $response = $client->get($uri); // Psr\Http\Message\StreamInterface $stream =

    $response->getBody(); $stream->getSize(); $stream->eof(); $stream->read(1024);
  4. PHP-HTTP/ADAPTER - SOLUTION public function __construct( Http\Adapter\HttpAdapter $adapter ) {

    $this->adapter = $adapter; } public function __construct( Http\Client\HttpClient $client ) { $this->client = $client; }
  5. PHP-HTTP/ADAPTER - COMPOSER.JSON "require": { - "guzzlehttp/guzzle": "^5.0", + "guzzlehttp/guzzle":

    "^6.0", "your-awesome/sdk": "^1.0",
 - "php-http/guzzle5-adapter": "^0.1.0" + "php-http/guzzle6-adapter": "^0.1.0" }
  6. • http:/ /mwl.be • https:/ /github.com/guzzle/guzzle • https:/ /github.com/php-http •

    http:/ /docs.guzzlephp.org/en/latest/ • https:/ /github.com/php-fig/http-message • https:/ /github.com/php-fig/fig-standards/
 blob/master/accepted/PSR-7-http-message.md REFERENCES