learn developing rest api in node.js using loopback framework

30
Welcome to Facebook Developer Circle Meetup * Date: Sunday, 26 Mar 2017 * Place: Ngalup.co, Mojolangu, Malang Last login: Sun Mar 26 09:00:00 2017 from 127.0.0.1 marudits@dev-circle-mlg:~$ _

Upload: marudi-subakti

Post on 15-Apr-2017

27 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Learn Developing REST API  in Node.js using LoopBack Framework

Welcome to Facebook Developer Circle Meetup

* Date: Sunday, 26 Mar 2017* Place: Ngalup.co, Mojolangu, Malang

Last login: Sun Mar 26 09:00:00 2017 from 127.0.0.1

marudits@dev-circle-mlg:~$ _

Page 2: Learn Developing REST API  in Node.js using LoopBack Framework

Learn Developing REST API in Node.js using LoopBack Framework

by Marudi Tri Subakti

Page 3: Learn Developing REST API  in Node.js using LoopBack Framework

Welcome to Facebook Developer Circle Meetup

* Date: Sunday, 26 Mar 2017* Place: Ngalup.co, Mojolangu, Malang

Last login: Sun Mar 26 09:00:00 2017 from 127.0.0.1

marudits@dev-circle-mlg:~$ whoami _

Page 4: Learn Developing REST API  in Node.js using LoopBack Framework

PART

1{ “name”: “Marudi Tri Subakti”, “phone”: “(+62) 85646628435”, “email”: “[email protected]”, “works”:[ { “company”: “PT Musica Studio’s”, “role”: “Web Developer”, }, { “company”: “Tebengan ID”, “role”: “Web Developer” } ]}

Page 5: Learn Developing REST API  in Node.js using LoopBack Framework

Welcome to Facebook Developer Circle Meetup

* Date: Sunday, 26 Mar 2017* Place: Ngalup.co, Mojolangu, Malang

Last login: Sun Mar 26 09:00:00 2017 from 127.0.0.1

marudits@dev-circle-mlg:~$ whoami

marudits@dev-circle-mlg:~$ man –k ‘REST API’ _

Page 6: Learn Developing REST API  in Node.js using LoopBack Framework

What is?

• Put it simply, REST = REpresentational State Transfer , is an architectural style define to help create and organize distributed system.

• It is not a guideline, not a standard, or anything that would imply that there are set a hard of rule to follow

3

PART

21

• There is no Request for Comments (RFC), which can leads to a widespread incomplete REST ideal

• But have set of contraints to define uniform interface: Client-Server, Stateless, Cacheable, Uniform Interface, Layered System, Code-on-Demand

Page 7: Learn Developing REST API  in Node.js using LoopBack Framework

Why?

• Performance, communication style is meant to be efficient and simple

3

PART

21

• Scalability, simple interaction greatly allow to handle heavy interaction

• Modifiability, separation of concerns allow to minimize risk

• Portability, can be implemented and consumed by many type of technology

• Reliability, allows for the easier recovery of system after failure

Page 8: Learn Developing REST API  in Node.js using LoopBack Framework

How it works? (Resources)

• Representations

3

PART

21

• Identifier

• Metadata

• Control Data

Page 9: Learn Developing REST API  in Node.js using LoopBack Framework

How it works? (Resources)

• Representations, it can be any way of representing data (binary, JSON, XML, etc)

3

PART

21

• Identifier

• Metadata

• Control Data

Page 10: Learn Developing REST API  in Node.js using LoopBack Framework

How it works? (Resources)

• Representations

3

PART

21

• Identifier, a URL that retrieves only one specific resource at any given time

• Metadata

• Control Data

Page 11: Learn Developing REST API  in Node.js using LoopBack Framework

How it works? (Resources)

• Representations

3

PART

21

• Identifier

• Metadata, Content-type, last-modified time, and so forth

• Control Data, is-modifiable-since, cache-control

Page 12: Learn Developing REST API  in Node.js using LoopBack Framework

Welcome to Facebook Developer Circle Meetup

* Date: Sunday, 26 Mar 2017* Place: Ngalup.co, Mojolangu, Malang

Last login: Sun Mar 26 09:00:00 2017 from 127.0.0.1

marudits@dev-circle-mlg:~$ whoami

marudits@dev-circle-mlg:~$ man –k ‘REST API’

marudits@dev-circle-mlg:~$ lb --help _

Page 13: Learn Developing REST API  in Node.js using LoopBack Framework

PART

342

What is?

• LoopBack framework is a set of Node.js modules that you can use independently or together to quickly build REST APIs

• Interacts with data sources through the LoopBack model API, available locally within Node.js, remotely over REST, and via native client APIs for iOS, Android, and HTML5

• Apps can query databases, store data, upload files, send emails, create push notifications, register users, and perform other actions provided by data sources and services.

Introduction

Page 14: Learn Developing REST API  in Node.js using LoopBack Framework

PART

342

What is?Architecture

Page 15: Learn Developing REST API  in Node.js using LoopBack Framework

• Create dynamic end-to-end REST APIs with little or no coding

PART

342

Why we use?

• Access data from various data source: major relational databases, MongoDB, SOAP and REST APIs

• Incorporate model relationships and access controls for complex APIs

• Separable components for file storage, third-party login, and OAuth 2.0

• MIT open-source license

Page 16: Learn Developing REST API  in Node.js using LoopBack Framework

PART

342

Why we use?

Loopback Express Sails Meteor

Type API Framework HTTP server library

Web MVC framework

Full-stack JavaScript app platform

Top Features

Enterprise connectivity, API Explorer, generators, client SDKs, websocket microservices

HTTP routing, middleware

Rails familiarity, MVC

Universal JavaScript, reactive rendering, websocket microservices

Suitable For

Web apps, APIs Simple web apps

Web apps, APIs Web apps

Clint SDKs

Angular, Browser, Node.js, iOS, Android, Xamarin

N/A None JavaScript, Cordova for iOS and Android, React, AngularJS

Data Source

In-memory/file, MongoDB, MySQL, Oracle, PostgreSQL, SQL Server, ATG, Email, REST, SOAP, many more.

None In-memory, File, PostgreSQL, MySQL, MongoDB

MongoDB, MySQL and PostgreSQL via 3rd-party packages

ACLs Yes No No Basic allow/deny

Comparation

Page 17: Learn Developing REST API  in Node.js using LoopBack Framework

PART

342

Why we use?

“By using LoopBack, we can build REST API easily with little or no coding, connect to various

datasources and define model relationship & its control access.”

Page 18: Learn Developing REST API  in Node.js using LoopBack Framework

PART

342

How it works?Core Concepts (Modules)

Page 19: Learn Developing REST API  in Node.js using LoopBack Framework

PART

342

How it works?

• Models : Dynamically mock-up models and expose them as APIs without worrying about persisting

(some) Key Features

• Abstraction : Connect to multiple data sources or services and get back an abstracted model with CRUD capabilities independent of backing data source.

• Data : Enable connections to RDBMS and noSQL data sources and get back an abstracted model

• ACL : Controls if a principal can perform a certain operation against a model.

• Remote Method : exposed remote method over a custom REST endpoint to perform operations not provided by LoopBack’s standard model REST API

• Remote Hook : executed before or after calling a remote method, either a custom remote method or a standard CRUD inherited from PersistedModel

Page 20: Learn Developing REST API  in Node.js using LoopBack Framework

PART

342

Getting Started• Install : Install the LoopBack CLI tool

$ npm install –g loopback-cli

• Create App : Create a “Hello World” LoopBack application$ lb

• Create Models : Generate models through CLI$ lb model

• Run : Run as you would any Node application $ node .

• Explore : Enables you to exercise all generated API endpoints http://127.0.0.1:3000/explorer

Page 21: Learn Developing REST API  in Node.js using LoopBack Framework

Welcome to Facebook Developer Circle Meetup

* Date: Sunday, 26 Mar 2017* Place: Ngalup.co, Mojolangu, Malang

Last login: Sun Mar 26 09:00:00 2017 from 127.0.0.1

marudits@dev-circle-mlg:~$ whoami

marudits@dev-circle-mlg:~$ man –k ‘REST API’

marudits@dev-circle-mlg:~$ lb --help

marudits@dev-circle-mlg:~$ npm run start _

Page 22: Learn Developing REST API  in Node.js using LoopBack Framework

CASE STUDY4

BAB

5 6

i

< />

{ }

Page 23: Learn Developing REST API  in Node.js using LoopBack Framework

BACKEND4

BAB

5 6

i

< />

{ }

http://loopback.io/

Page 24: Learn Developing REST API  in Node.js using LoopBack Framework

BACKEND4

BAB

5 6

i

< />

{ }

/* install loopback */$ npm install –g loopback-cli

/* create app */$ lb/* create models */$ lb model

/* attach to datasource */$ lb datasource

/* define relations */$ lb relation

/* run app */$ node .

/* develop your own */

/* set access control */$ lb acl

Page 25: Learn Developing REST API  in Node.js using LoopBack Framework

FRONTEND4

BAB

5 6

i

< />

{ }

https://ant.design/

Page 26: Learn Developing REST API  in Node.js using LoopBack Framework

FRONTEND4

BAB

5 6

i

< />

{ }

/* install antd-init generator */$ npm install –g antd-init

/* make and move to app directory */$ mkdir helloworld && cd helloworld

/* create app */$ antd-init

/* run app */$ npm start

/* develop your own */

Page 27: Learn Developing REST API  in Node.js using LoopBack Framework

Welcome to Facebook Developer Circle Meetup

* Date: Sunday, 26 Mar 2017* Place: Ngalup.co, Mojolangu, Malang

Last login: Sun Mar 26 09:00:00 2017 from 127.0.0.1

marudits@dev-circle-mlg:~$ whoami

marudits@dev-circle-mlg:~$ man –k ‘REST API’

marudits@dev-circle-mlg:~$ lb --help

marudits@dev-circle-mlg:~$ npm run start

marudits@dev-circle-mlg:~$ ping tebengan.id _

Page 28: Learn Developing REST API  in Node.js using LoopBack Framework

Should our stories resonate with you, why not share your stories and aspiration with us

and help build tebengan together (?)

[email protected]

Page 29: Learn Developing REST API  in Node.js using LoopBack Framework

Welcome to Facebook Developer Circle Meetup

* Date: Sunday, 26 Mar 2017* Place: Ngalup.co, Mojolangu, Malang

Last login: Sun Mar 26 09:00:00 2017 from 127.0.0.1

marudits@dev-circle-mlg:~$ whoami

marudits@dev-circle-mlg:~$ man –k ‘REST API’

marudits@dev-circle-mlg:~$ lb --help

marudits@dev-circle-mlg:~$ npm run start

marudits@dev-circle-mlg:~$ ping tebengan.id

marudits@dev-circle-mlg:~$ shutdown –h now _

Page 30: Learn Developing REST API  in Node.js using LoopBack Framework

Learn Developing REST API in Node.js using LoopBack Framework

by Marudi Tri Subakti