Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Expressive Microservice Framework Blastoff

1,127 views

Published on

With PHP frameworks being more decoupled than ever, and with the help of a package and dependency manager, large and heavy PHP frameworks are becoming a thing of the past. Modern PHP developers now have a wealth of libraries available that specialize at specific tasks, and microservices are fast becoming a preferred way to architect applications. But many don't know how to start.

This talk will briefly introduce what microservices are, and how to use them. Then show how to build a foundation using the Zend Expressive microframework leveraging components of Zend Framework, and other libraries, to quickly create awesome things without requiring an entire framework. Resources for reference and continued learning will also be shared.

Published in: Technology
  • Be the first to comment

Expressive Microservice Framework Blastoff

  1. 1. Expressive Microservice Framework Blastoff By: Adam Culp Twitter: @adamculp https://joind.in/talk/cd0e6
  2. 2. 2 Expressive Microservice Framework Blastoff ● About me – OSS Contributor – PHP Certified – Zend Certification Advisory Board – PHP-Fig voting member (IBM i Toolkit) – Consultant at Zend Technologies – Organizer SoFloPHP (South Florida) – Organizer SunshinePHP (Miami) – Long distance (ultra) runner – Photography Enthusiast – Judo Black Belt Instructor
  3. 3. 3 Expressive Microservice Framework Blastoff ● About me – OSS Contributor – PHP Certified – Zend Certification Advisory Board – PHP-Fig voting member (IBM i Toolkit) – Consultant at Zend Technologies – Organizer SoFloPHP (South Florida) – Organizer SunshinePHP (Miami) – Long distance (ultra) runner – Photography Enthusiast – Judo Black Belt Instructor I am the PHP Ninja!!!
  4. 4. 4 Expressive Microservice Framework Blastoff ● I Help Build The Web
  5. 5. 5 Expressive Microservice Framework Blastoff ● Frameworks Suck – Complicated ● Routing ● Databases ● Connectivity ● Communication (HTTP, API) ● Information Container ● GUI (html, javascript, templates, CSS,) ● Errors and Exceptions ● Validation and Cleansing Data ● State
  6. 6. 6 Expressive Microservice Framework Blastoff ● Frameworks Web Applications Suck – Complicated ● Routing ● Databases ● Connectivity ● Communication (HTTP, API) ● Information Container ● GUI (html, javascript, templates, CSS,) ● Errors and Exceptions ● Validation and Cleansing Data ● State
  7. 7. 7 Expressive Microservice Framework Blastoff ● Buzzword Bingo – We will mention many buzzwords, but...
  8. 8. 8 Expressive Microservice Framework Blastoff ● Microservice – All the buzz is “microservices”. – ...complex applications are composed of small, independent processes communicating with each other using language-agnostic APIs. These services are small building blocks, highly decoupled and focused on doing a small task, facilitating a modular approach to system-building. – Wikipedia
  9. 9. 9 Expressive Microservice Framework Blastoff ● But in PHP... – How to keep microservices light? – Microservices shouldn’t be heavy I’m a Microservice!!!
  10. 10. 10 Expressive Microservice Framework Blastoff ● Full Stack Frameworks Suck – Heavy, bloated, slow – “Lock” you in – “Kitchen Sink” – “You don’t need everything, but its there...”
  11. 11. 11 Expressive Microservice Framework Blastoff ● Need For Speed – What does a microservice “need”? ● HTTP message layer ● Routing capabilities ● Dependency injection – IoC – Testable – Swappable pieces ● Templating – Optional (APIs may not need it, except documentation)
  12. 12. 12 Expressive Microservice Framework Blastoff ● PHP Ecosystem Facilitators – Composer – Components – Libraries – Containers – Microframeworks – PHP 7
  13. 13. 13 Expressive Microservice Framework Blastoff ● All The Things!!! – So many tools: Monolog Whoops Flysystem IBMiToolkit OAuth2 Server https://github.com/ziadoz/awesome-php Expressive
  14. 14. 14 Expressive Expressive Microservice Framework Blastoff ● Communication Sucks – Say what!?! Monolog Whoops Flysystem IBMiToolkit OAuth2 Server
  15. 15. 15 Expressive Microservice Framework Blastoff ● PSR-15 (preferred) – Part of PHP-Fig.org recommendations – Must implement ● PsrHttpServerMiddlewareMiddlewareInterface ● Middleware dispatching systems must implement – PsrHttpServerMiddlewareDelegateInterface – PSR-7 Double Pass ● PsrHttpMessageMessageInterface – PsrHttpMessageRequestInterface ● PsrHttpMessageServerRequestInterface – PsrHttpMessageResponseInterface ● PsrHttpMessageStreamInterface ● PsrHttpMessageUploadFileInterface ● PsrHttpMessageUriInterface
  16. 16. 16 Expressive Microservice Framework Blastoff ● Middleware – ...Middleware makes it easier for software developers to implement communication and input/output, so they can focus on the specific purpose of their application. – Wikipedia – Lighter applications (only what is needed) – Composed of layers
  17. 17. 17 Expressive Microservice Framework Blastoff ● Zend Expressive – Microframework built around middleware – Versions ● Version 1 based on PSR-7 ● Version 2 based on PSR-15 – Very lean runtime – Use for building: ● APIs ● Web applications ● Single page sites – Choose your own stack – Great documentation ● https://zendframework.github.io/zend-expressive/
  18. 18. 18 Expressive Microservice Framework Blastoff ● Zend Expressive – Not built on Zend Framework, but build by ZF team ● Zend Framework 3 does include some components now ● You choose the stack
  19. 19. 19 Expressive Microservice Framework Blastoff ● Composer Install Script – Done right from the start All code available at: https://github.com/adamculp/expressive-blastoff
  20. 20. 20 Expressive Microservice Framework Blastoff ● Composer Install Script
  21. 21. 21 Expressive Microservice Framework Blastoff ● Composer Install Script – Minimal skeleton or full? ● With or without samples ● Flat or with modules!
  22. 22. 22 Expressive Microservice Framework Blastoff ● Composer Install Script – Container options: (container interop) ● Aura.Di ● Pimple ● Zend ServiceManager*
  23. 23. 23 Expressive Microservice Framework Blastoff ● Composer Install Script – Router options ● Aura.Router ● FastRoute* ● Zend Router
  24. 24. 24 Expressive Microservice Framework Blastoff ● Composer Install Script – Template engine options: ● Plates ● Twig ● Zend View ● None*
  25. 25. 25 Expressive Microservice Framework Blastoff ● Composer Install Script – Error handler options: ● Whoops* ● None
  26. 26. 26 Expressive Microservice Framework Blastoff ● Structure – Folder structure of Zend Expressive Skeleton
  27. 27. 27 Expressive Microservice Framework Blastoff ● Skeleton Application
  28. 28. 28 Expressive Microservice Framework Blastoff ● Not MVC – Files and structure focused on Actions
  29. 29. 29 Expressive Microservice Framework Blastoff ● The Flow
  30. 30. 30 Expressive Microservice Framework Blastoff ● Initial File – Front controller (/public/index.php)
  31. 31. 31 Expressive Microservice Framework Blastoff ● Container Creation – We specified Zend ServiceManager (/config/container.php)
  32. 32. 32 Expressive Microservice Framework Blastoff ● Load Configs (/config/config.php)
  33. 33. 33 Expressive Microservice Framework Blastoff ● Load Configs (/src/App/src/ConfigProvider.php)
  34. 34. 34 Expressive Microservice Framework Blastoff ● Load More Configs
  35. 35. 35 Expressive Microservice Framework Blastoff ● Load Pipelines – Items to be called as the middleware pipeline. (/config/pipeline.php)
  36. 36. 36 Expressive Microservice Framework Blastoff ● Load Pipelines – Items to be called as routed middleware. (/config/routes.php)
  37. 37. 37 Expressive Microservice Framework Blastoff ● Action Anatomy – Creates raw JSON response (/src/App/src/Action/PingAction.php)
  38. 38. 38 Expressive Microservice Framework Blastoff ● JSON Response – Created by action
  39. 39. 39 Expressive Microservice Framework Blastoff ● Let’s Create a Middleware!!!
  40. 40. 40 Expressive Microservice Framework Blastoff ● Header Middleware – Create class for new middleware (or include someone else’s)
  41. 41. 41 Expressive Microservice Framework Blastoff ● Header Middleware – The class to include the very important header (/src/App/src/Middleware/TheClacksMiddleware.php)
  42. 42. 42 Expressive Microservice Framework Blastoff ● Header Middleware – Add the middleware to the pipeline – It will always be included (/config/pipeline.php)
  43. 43. 43 Expressive Microservice Framework Blastoff ● Header Middleware – Header for every call now carries our important message
  44. 44. 44 Expressive Microservice Framework Blastoff ● Let’s Create a Database Connected Middleware!!! ● With Zend Db
  45. 45. 45 Expressive Microservice Framework Blastoff ● Database Connected Example With Zend Db – First we need a database connection. ● Will use Zend-Db for this example, but could be anything. ● Composer to the rescue!
  46. 46. 46 Expressive Microservice Framework Blastoff ● Database Connected Example With Zend Db – Specify adapter (via Zend/Db/ConfigProvider() in this case) (/config/config.php)
  47. 47. 47 Expressive Microservice Framework Blastoff ● Database Connected Example With Zend Db – Provide local/instance configuration ● This would be driver and credentials ● (credentials not needed with sqlite) (/config/autoload/db.local.php)
  48. 48. 48 Expressive Microservice Framework Blastoff ● Database Connected Example With Zend Db – Add the new action to dependencies (/config/autoload/routes.global.php)
  49. 49. 49 Expressive Microservice Framework Blastoff ● Database Connected Example With Zend Db – Add the new route to dependencies (/config/routes.php
  50. 50. 50 Expressive Microservice Framework Blastoff ● Database Connected Example With Zend Db – Create a factory to pass items needed by the action (/src/App/src/Action/UserListFactory.php)
  51. 51. 51 Expressive Microservice Framework Blastoff ● Database Connected Example With Zend Db – Create the action (view 1 of 2 - constructor) (/src/App/src/Action/UserListAction.php)
  52. 52. 52 Expressive Microservice Framework Blastoff ● Database Connected Example With Zend Db – Create the action (view 2 of 2 - __invoke method) (/src/App/src/Action/UserListAction.php cont’d)
  53. 53. 53 Expressive Microservice Framework Blastoff ● Database Connected Example With Zend Db – Create the view template (/templates/app/user-list.phtml)
  54. 54. 54 Expressive Microservice Framework Blastoff ● Database Connected Example With Zend Db – Rejoice!
  55. 55. 64 Expressive Microservice Framework Blastoff ● With Zend Expressive: – Easy to build middleware – Lightweight, add what is really needed – Fast – no extra load – Microservices in PHP are better
  56. 56. 65 Expressive Microservice Framework Blastoff ● Give Zend Expressive a Try...Today!!! – https://zendframework.github.io/zend-expressive/
  57. 57. ● Thank you! ● Code at: https://github.com/adamculp/expressive-blastoff ● Please rate at: https://joind.in/talk/cd0e6 Adam Culp http://www.rungeekradio.com http://www.geekyboy.com Twitter @adamculp Expressive Microservice Framework Blastoff

×