O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.

Putting legacy to REST with middleware

We fear modernizing legacy applications, or going API first. But it's not as futile as you might think. With modern PHP microframeworks geared toward middleware it can be a breeze.

Now the truth: It is a terribly difficult task full of pitfalls. But I will share how to do it in a step-by-step method that makes it much more approachable, and enable you to be a super hero.

  • Entre para ver os comentários

  • Seja a primeira pessoa a gostar disto

Putting legacy to REST with middleware

  1. 1. Putting Legacy to REST with Middleware By: Adam Culp Twitter: @adamculp
  2. 2. 2 Putting Legacy to REST with Middleware ● About me – DevRel and Tech Lead at Nexmo – OSS Contributor – PHP-Fig voting member (IBM i Toolkit) – Organizer SoFloPHP (South Florida) – Organizer SunshinePHP (Miami) – Long distance (ultra) runner – Judo Black Belt Instructor
  3. 3. 3 Putting Legacy to REST with Middleware ● About me – DevRel and Tech Lead at Nexmo – OSS Contributor – PHP-Fig voting member (IBM i Toolkit) – Organizer SoFloPHP (South Florida) – Organizer SunshinePHP (Miami) – Long distance (ultra) runner – Judo Black Belt Instructor I am the PHP Ninja!!!
  4. 4. 4 Putting Legacy to REST with Middleware ● Fan of iteration – Pretty much everything requires iteration to do well: ● Long distance running ● Judo ● Development ● Evading project managers ● Refactoring!
  5. 5. 5 Refactoring Legacy Code ● What is “Legacy Code”? – Is there a coding standard for your project?
  6. 6. 6 Refactoring Legacy Code ● What is “Legacy Code”? – Is there a coding standard for your project? – Is code using OOP?
  7. 7. 7 Refactoring Legacy Code ● What is “Legacy Code”? – Is there a coding standard for your project? – Is code using OOP? – Is Composer used in your project?
  8. 8. 8 Refactoring Legacy Code ● What is “Legacy Code”? – Is there a coding standard for your project? – Is code using OOP? – Is Composer used in your project? – Is the project using a framework?
  9. 9. 9 Refactoring Legacy Code ● What is “Legacy Code”? – Is there a coding standard for your project? – Is code using OOP? – Is Composer used in your project? – Is the project using a framework? – Are you unit testing?
  10. 10. 10 Refactoring Legacy Code ● What is “Legacy Code”? – Is there a coding standard for your project? – Is code using OOP? – Is Composer used in your project? – Is the project using a framework? – Are you unit testing? – Does your project avoid NIH?
  11. 11. 11 Refactoring Legacy Code ● What is “Legacy Code”? – Is there a coding standard for your project? – Is code using OOP? – Is Composer used in your project? – Is the project using a framework? – Are you unit testing? – Does your project avoid NIH? If you can answer “No” to any of these, you may be creating “Legacy Code”!!!
  12. 12. 12 Refactoring Legacy Code ● What is “legacy” really? – According to https://en.wikipedia.org/wiki/Legacy_code ● “...no longer supported or manufactured...” ● “...code inserted into modern software for the purpose of maintaining an older or previously supported feature...” ● “...supporting older file formats...” ● “...code may no longer work without changes...” ● “...code that no longer runs on a later version of a system, or requires a compatibility layer to do so...”
  13. 13. 13 Putting Legacy to REST with Middleware ● Why Rewrite? – Change technology (PHP to Javascript, Python, etc.) – Code is REALLY bad – If less expensive to rewrite versus refactor – Little to no chance to lose business logic – Desire a “different” application
  14. 14. 14 Putting Legacy to REST with Middleware ● API First! – API is first class citizen
  15. 15. 15 Putting Legacy to REST with Middleware ● API First! – API is first class citizen – API comes first, then implementation
  16. 16. 16 Putting Legacy to REST with Middleware ● API First! – API is first class citizen – API comes first, then implementation – Development teams can work in parallel
  17. 17. 17 Putting Legacy to REST with Middleware ● API First! – API is first class citizen – API comes first, then implementation – Development teams can work in parallel – Reduces cost of developing apps ● Through re-use of business logic
  18. 18. 18 Putting Legacy to REST with Middleware ● API First! – API is first class citizen – API comes first, then implementation – Development teams can work in parallel – Reduces cost of developing apps ● Through re-use of business logic – Faster time to market
  19. 19. 19 Putting Legacy to REST with Middleware ● API First! – API is first class citizen – API comes first, then implementation – Development teams can work in parallel – Reduces cost of developing apps ● Through re-use of business logic – Faster time to market – OpenAPI
  20. 20. 20 Putting Legacy to REST with Middleware ● API First! – API is first class citizen – API comes first, then implementation – Development teams can work in parallel – Reduces cost of developing apps ● Through re-use of business logic – Faster time to market – OpenAPI – Reduces risk of failure
  21. 21. 21 Putting Legacy to REST with Middleware ● Modernization Methods
  22. 22. 22 Putting Legacy to REST with Middleware ● Modernization Methods – #1 Total Rewrite ● Create entirely new app ● Build until complete ● Big BANG!
  23. 23. 23 Putting Legacy to REST with Middleware ● Modernization Methods – #1 Total Rewrite ● Create entirely new app ● Build until complete ● Big BANG!
  24. 24. 24 Putting Legacy to REST with Middleware ● Modernization Methods – #1 Total Rewrite ● Create entirely new app ● Build until complete ● Big BANG! ● Pitfalls – Constant “scope creep” – Maintain 2 apps – Expensive!
  25. 25. 25 Putting Legacy to REST with Middleware ● Modernization Methods – #1 Total Rewrite ● Create entirely new app ● Build until complete ● Big BANG! ● Pitfalls – Constant “scope creep” – Maintain 2 apps – Expensive! ● Benefits – Clean slate – Energy/Excitement – Less business disruption
  26. 26. 26 Putting Legacy to REST with Middleware ● Modernization Methods (cont’d) – #2 REST API Backend ● Build an API ● Use the API to drive logic and data
  27. 27. 27 Putting Legacy to REST with Middleware ● Modernization Methods (cont’d) – #2 REST API Backend ● Build an API ● Use the API to drive logic and data ● Pitfalls – Requires cleanup of objects first – Longer time to get productive – Very difficult for spaghetti apps
  28. 28. 28 Putting Legacy to REST with Middleware ● Modernization Methods (cont’d) – #2 REST API Backend ● Build an API ● Use the API to drive logic and data ● Pitfalls – Requires cleanup of objects first – Longer time to get productive – Very difficult for spaghetti apps ● Benefits – Cleans up data/business logic – Shorter time to completion
  29. 29. 29 Putting Legacy to REST with Middleware ● Modernization Methods #2 (How-To) – Create standalone REST API ● Add one module at a time
  30. 30. 30 Putting Legacy to REST with Middleware ● Modernization Methods #2 (How-To) – Create standalone REST API ● Add one module at a time – Refactor the Legacy application to use API as Service/Model
  31. 31. 31 Putting Legacy to REST with Middleware ● Modernization Methods #2 (How-To) – Create standalone REST API ● Add one module at a time – Refactor the Legacy application to use API as Service/Model – Eventually API First, w/ frontend application
  32. 32. 32 Putting Legacy to REST with Middleware ● Modernization Methods (cont’d) – #3 Legacy Middleware ● New application (as with rewrite) ● In stages
  33. 33. 33 Putting Legacy to REST with Middleware ● Modernization Methods (cont’d) – #3 Legacy Middleware ● New application (as with rewrite) ● In stages ● Pitfalls – Takes upfront planning – Takes longer – Overall, still creating 2 new apps – Not API first until the end
  34. 34. 34 Putting Legacy to REST with Middleware ● Modernization Methods (cont’d) – #3 Legacy Middleware ● New application (as with rewrite) ● In stages ● Pitfalls – Takes more planning – Takes longer – Overall, still creating 2 new apps – Not API first until the end ● Benefits – Can update/implement new frontend faster (duplicated) – Spaghetti app easier to manage – Less business impact – Marketing “new” features regularly
  35. 35. 35 Putting Legacy to REST with Middleware ● Modernization Methods #3 (How-To) – New sub-directory for new app
  36. 36. 36 Putting Legacy to REST with Middleware ● Modernization Methods #3 (How-To) – New sub-directory for new app – Create LegacyMiddleware, add it before FinalMiddleware
  37. 37. 37 Putting Legacy to REST with Middleware ● Modernization Methods #3 (How-To) – New sub-directory for new app – Create LegacyMiddleware, add it before FinalMiddleware – Fix issues with routing and includes
  38. 38. 38 Putting Legacy to REST with Middleware ● Modernization Methods #3 (How-To) – New sub-directory for new app – Create LegacyMiddleware, add it before FinalMiddleware – Fix issues with routing and includes – Update doc_root to be new location ● Site working as it used to
  39. 39. 39 Putting Legacy to REST with Middleware ● Modernization Methods #3 (How-To) – New sub-directory for new app – Create LegacyMiddleware, add it before FinalMiddleware – Fix issues with routing and includes – Update doc_root to be new location ● Site working as it used to – Start creating new modules in new app
  40. 40. 40 Putting Legacy to REST with Middleware ● Modernization Methods #3 (How-To) – New sub-directory for new app – Create LegacyMiddleware, add it before FinalMiddleware – Fix issues with routing and includes – Update doc_root to be new location ● Site working as it used to – Start creating new modules in new app – LegacyMiddleware called less and less
  41. 41. 41 Putting Legacy to REST with Middleware ● Modernization Methods #3 (How-To) – New sub-directory for new app – Create LegacyMiddleware, add it before FinalMiddleware – Fix issues with routing and includes – Update doc_root to be new location ● Site working as it used to – Start creating new modules in new app – LegacyMiddleware called less and less – Remove legacy app once all endpoints satisfied
  42. 42. 42 Putting Legacy to REST with Middleware ● What is “Middleware”? – NEW? way to build multi-layers as tiered approach to execution – “Software glue” - wikipedia ● Implement communication and input/output ● Popular in ‘80s to link newer applications to legacy systems
  43. 43. 43 Putting Legacy to REST with Middleware ● Frameworks! – Expressive (Laminas Project, formerly Zend Framework) – Slim PHP – Most others: ● Laravel ● Symfony ● Etc.
  44. 44. 44 Putting Legacy to REST with Middleware ● Testing – Always test prior to refactoring – Then refactor – Then test again – Refactor tests as needed – Repeat
  45. 45. 45 Putting Legacy to REST with Middleware ● Tools – Source Control ● Allows easier rollback ● Allows collaboration ● Git makes branching easier
  46. 46. 46 Putting Legacy to REST with Middleware ● Tools (cont’d) – CI/CD ● Makes updates across team seamless
  47. 47. 47 Putting Legacy to REST with Middleware ● Conclusion – Middleware makes modernization easier – Do it in stages – Test all the things...often – Teamwork – Love iteration!
  48. 48. 48 Putting Legacy to REST with Middleware ● Go! – Your turn!
  49. 49. ● Thank you! – Code: https://github.com/adamculp/ Adam Culp https://beachcasts.com https://geekyboy.com https://rungeekradio.com Twitter @adamculp Questions?

×