Modern HTTP handling with PHP - Dutch PHP conference

Modern HTTP handling with PHP - Dutch PHP conference

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.

Feedback here: https://joind.in/talk/1786a

39eb3f3d313b13f05534e496285040b8?s=128

Hannes Van De Vreken

June 25, 2016
Tweet

Transcript

  1. 1.
  2. 3.

    !

  3. 5.
  4. 6.
  5. 11.

    Common interfaces for HTTP messages - Works in any Framework

    - Both for HTTP Clients and HTTP applications - HTTP version independent
  6. 13.
  7. 24.

  8. 30.
  9. 31.
  10. 38.

    GUZZLEHTTP/GUZZLE - PROMISES use Psr\Http\Message\ResponseInterface as Res; $promise = $client->sendAsync($request);

    $promise->then(function (Res $response) { $response->getBody(); }); $promise->wait();
  11. 43.

    GUZZLEHTTP/GUZZLE - MIDDLEWARES $middleware = function ($handler) { return function

    ($request, $options) use ($handler) // Alter request, if you want return $handler($request, $options) ->then(function (ResponseInterface $respons // Alter response, if you want return $response; }); }; }
  12. 55.

    PHP-HTTP/HTTPLUG - ADAPTERS guzzle6-adapter guzzle5-adapter guzzle4-adapter guzzle3-adapter zend2-adapter zend1-adapter cake-adapter

    buzz-adapter react-adapter socket-client fopen-adapter file-get-contents-adapter curl-client mock-client
  13. 57.

    PHP-HTTP/HTTPLUG - 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" }
  14. 61.

    START USING PSR-7 IN YOUR APP Symfony request/response object ⁷

    ⁷ Zend request/response object \Psr\Http\Message\RequestInterface type hinted
  15. 63.
  16. 65.

    MIDDLEWARE DEFINITION function ($request, $response, $next) { // Alter request,

    if you want $response = $next($request, $response); // Alter response, if you want return $response; }
  17. 80.

    • 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