Loopback API Framework

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

Resources

Loopback: http://loopback.io/
Getting started: http://loopback.io/getting-started/
Create a simple API: https://docs.strongloop.com/display/public/LB/Create+a+simple+API
LoopBack core concepts: https://docs.strongloop.com/display/public/LB/LoopBack+core+concepts

Build an App named loopback-getting-started

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
$ npm install -g strongloop
# Create app
$ slc loopback
_-----_
| | .--------------------------.
|--(o)--| | Let's create a LoopBack |
`---------´ | application! |
( _´U`_ ) '--------------------------'
/___A___\
| ~ |
__'.___.'__
´ ` |° ´ Y `
[?] What's the name of your application? loopback-getting-started
[?] Enter name of the directory to contain the project: loopback-getting-started
# Create model people
$ cd loopback-getting-started
$ slc loopback:model
[?] Enter the model name: people
[?] Select the data-source to attach people to: db (memory)
[?] Select model's base class PersistedModel
[?] Expose people via the REST API? Yes
[?] Custom plural form (used to build REST URL):
[?] Common model or server only? common
Let's add some people properties now.
Enter an empty property name when done.
[?] Property name: firstname
invoke loopback:property
[?] Property type: string
[?] Required? Yes
Let's add another people property.
Enter an empty property name when done.
[?] Property name: lastname
invoke loopback:property
[?] Property type: string
[?] Required? Yes
Let's add another people property.
Enter an empty property name when done.
# Create another model CoffeeShop
$ slc loopback:model
[?] Enter the model name: CoffeeShop
[?] Select the data-source to attach CoffeeShop to: db (memory)
[?] Select model's base class PersistedModel
[?] Expose CoffeeShop via the REST API? Yes
[?] Custom plural form (used to build REST URL):
[?] Common model or server only? common
Let's add some CoffeeShop properties now.
Enter an empty property name when done.
[?] Property name: name
invoke loopback:property
[?] Property type: string
[?] Required? Yes
Let's add another CoffeeShop property.
Enter an empty property name when done.
[?] Property name: city
invoke loopback:property
[?] Property type: string
v Required? Yes
Let's add another CoffeeShop property.
Enter an empty property name when done.
[?] Property name:
# Run the application
$ node .
Web server listening at: http://0.0.0.0:3000
Browse your REST API at http://0.0.0.0:3000/explorer

project structure

  • server - Node application scripts and configuration files.
  • common[server]/models sub-directory contains all model JSON and JavaScript files.
  • client - Client JavaScript, HTML, and CSS files.
  • common - Files common to client and server.

loopback project structure

Use API Explorer

Goto http://0.0.0.0:3000:

1
{"started":"2016-01-14T08:05:00.339Z","uptime":48.7}

Goto http://0.0.0.0:3000/explorer:

Loopback API Explorer

Create a new instance of the model and persist it into the data source

API: POST /CoffeeShops
POST API
application's response after post data

Retrieve the data inside datasource

API: GET /CoffeeShops
GET API
get data

Contents
  1. 1. Resources
  2. 2. Build an App named loopback-getting-started
  3. 3. Use API Explorer
    1. 3.1. Create a new instance of the model and persist it into the data source
    2. 3.2. Retrieve the data inside datasource
|