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

Customizing Loopback - Integrating More Modules

David Okun
February 21, 2017

Customizing Loopback - Integrating More Modules

Loopback is a great tool that allows you to generate an Express.js API from the command line. In this talk, I show you how you can take advantage of the Node.js ecosystem and integrate other modules into a Loopback API as business logic.

David Okun

February 21, 2017

More Decks by David Okun

Other Decks in Programming


  1. Customizing Loopback – Integrating More Modules David Okun, Developer Evangelist,

    Strongloop & [email protected] @dokun24 February 21, 2017
  2. What is a Loopback? • THE easiest & fastest way

    to set up a RESTful web API. • Uses Express, Node, and Yeoman. • Get an API up with writing zero code.
  3. Extending Your API – The Scenario • We have two

    immutable microservices. • We want to combine their output and cache it locally.
  4. Aren’t Microservices Adorable?

  5. Today’s Modules • request • https://npmjs.com/package/request

  6. Today’s Modules • request-promise & bluebird • https://npmjs.com/package/request- promise •

  7. Setup • Node.js & npm (I’m running 7.4.0 and 4.0.5)

    • npm install –g loopback • npm install –g strongloop
  8. Our Microservices

  9. Today’s Demo • The finished product can be found at:

    • https://github.com/dokun1/LoopbackModulesDemo
  10. Our Microservices – Up And Running

  11. Loopback!

  12. In-Memory Datasource

  13. Setting up our Animal object

  14. Model…

  15. Model…

  16. Model…

  17. Model…

  18. Sanity Check

  19. Sanity Check

  20. Remote Methods • A remote method is a method of

    a model. • Can be made with lb remote-method.
  21. Animal.js

  22. Remote Hooks • A remote hook is a function that

    can be executed before or after a remote method is called. • beforeRemote(), afterRemote(), afterRemoteError().
  23. Animal.js

  24. Operation Hooks • An operation hook is a function triggered

    on a higher-order function of a PersistedModel object.
  25. Operation Hooks (cont.)

  26. Animal.js

  27. Animal.js

  28. Animal.js

  29. And we’re clear!!

  30. But actually… • We aren’t validating the entries we get,

    so we always get duplicates.
  31. Animal.js

  32. Animal.js

  33. Animal.js

  34. Animal.js

  35. And we’re clear!!

  36. Bonus Points: Validators • Model objects can use a set

    of common validators for convenience. • Only supported with in-memory, Oracle, and MongoDB.
  37. Animal.js

  38. Wrapping up • Loopback isn’t just for POCs – rather

    than limiting you to generated code, it supports what you want to build. • It gets out of the way when you need it to.
  39. Resources • https://loopback.io • Adding logic: https://loopback.io/doc/en/lb3/Adding-application-logic.html • Demo Repo:

    https://github.com/dokun1/LoopbackModulesDemo • Stack Overflow: http://stackoverflow.com/questions/tagged/loopback • Me on Twitter: @dokun24
  40. Thank You!!!