Slide 1

Slide 1 text

Customizing Loopback – Integrating More Modules David Okun, Developer Evangelist, Strongloop & Swift@IBM @dokun24 February 21, 2017

Slide 2

Slide 2 text

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.

Slide 3

Slide 3 text

Extending Your API – The Scenario • We have two immutable microservices. • We want to combine their output and cache it locally.

Slide 4

Slide 4 text

Aren’t Microservices Adorable?

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

Setup • Node.js & npm (I’m running 7.4.0 and 4.0.5) • npm install –g loopback • npm install –g strongloop

Slide 8

Slide 8 text

Our Microservices

Slide 9

Slide 9 text

Today’s Demo • The finished product can be found at: • https://github.com/dokun1/LoopbackModulesDemo

Slide 10

Slide 10 text

Our Microservices – Up And Running

Slide 11

Slide 11 text

Loopback!

Slide 12

Slide 12 text

In-Memory Datasource

Slide 13

Slide 13 text

Setting up our Animal object

Slide 14

Slide 14 text

Model…

Slide 15

Slide 15 text

Model…

Slide 16

Slide 16 text

Model…

Slide 17

Slide 17 text

Model…

Slide 18

Slide 18 text

Sanity Check

Slide 19

Slide 19 text

Sanity Check

Slide 20

Slide 20 text

Remote Methods • A remote method is a method of a model. • Can be made with lb remote-method.

Slide 21

Slide 21 text

Animal.js

Slide 22

Slide 22 text

Remote Hooks • A remote hook is a function that can be executed before or after a remote method is called. • beforeRemote(), afterRemote(), afterRemoteError().

Slide 23

Slide 23 text

Animal.js

Slide 24

Slide 24 text

Operation Hooks • An operation hook is a function triggered on a higher-order function of a PersistedModel object.

Slide 25

Slide 25 text

Operation Hooks (cont.)

Slide 26

Slide 26 text

Animal.js

Slide 27

Slide 27 text

Animal.js

Slide 28

Slide 28 text

Animal.js

Slide 29

Slide 29 text

And we’re clear!!

Slide 30

Slide 30 text

But actually… • We aren’t validating the entries we get, so we always get duplicates.

Slide 31

Slide 31 text

Animal.js

Slide 32

Slide 32 text

Animal.js

Slide 33

Slide 33 text

Animal.js

Slide 34

Slide 34 text

Animal.js

Slide 35

Slide 35 text

And we’re clear!!

Slide 36

Slide 36 text

Bonus Points: Validators • Model objects can use a set of common validators for convenience. • Only supported with in-memory, Oracle, and MongoDB.

Slide 37

Slide 37 text

Animal.js

Slide 38

Slide 38 text

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.

Slide 39

Slide 39 text

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

Slide 40

Slide 40 text

Thank You!!!