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

Modern HTTP handling with PHP - Meetup PHP Leuven

Modern HTTP handling with PHP - Meetup PHP Leuven

PSR-7 describes common interfaces for representing HTTP messages. HTTP messages are the foundation of web development. Web browsers and HTTP clients such as cURL create HTTP request messages that are sent to a web server, which provides an HTTP response message. Server-side code receives an HTTP request message, and returns an HTTP response message. Hannes Van De Vreken (madewithlove) will talk about the impact of PSR-7 on the way frameworks implement these messages, and give a few live examples.

Hannes Van De Vreken

September 03, 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); $stack->remove($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