on
Italy
- Get link
- X
- Other Apps
What’s LoopBack? It’s an open source Node.js framework for composing and securing APIs and getting them connected to your data.


|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
$ mkdir Xamarin_Node_API
$ cd Xamarin_Node_API/
$ slc loopback
_-----_
| | .--------------------------.
|--(o)--| | Let's create a LoopBack |
`---------´ | application! |
( _´U`_ ) '--------------------------'
/___A___\
| ~ |
__'.___.'__
´ ` |° ´ Y `
? What's the name of your application? Server
? Enter name of the directory to contain the project: Server
|
|
1
2
3
4
5
6
7
8
|
$ cd Server
$ slc loopback:model
? Enter the model name: TodoTask
? Select the data-source to attach TodoTask to: db (memory)
? Select model's base class: PersistedModel
? Expose TodoTask via the REST API? Yes
? Custom plural form (used to build REST URL):
Let's add some TodoTask properties now.
|
|
1
2
3
4
5
6
7
8
9
10
11
12
|
Enter an empty property name when done.
? Property name: title
invoke loopback:property
? Property type: (Use arrow keys)
❯ string
number
boolean
object
array
date
buffer
(Move up and down to reveal more choices)
|
|
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
|
? Required? Yes
Let's add another TodoTask property.
Enter an empty property name when done.
? Property name: date
invoke loopback:property
? Property type: date
? Required? Yes
Let's add another TodoTask property.
Enter an empty property name when done.
? Property name: isDone
invoke loopback:property
? Property type: boolean
? Required? Yes
Let's add another TodoTask property.
Enter an empty property name when done.
? Property name: isDeleted
invoke loopback:property
? Property type: boolean
? Required? Yes
Let's add another TodoTask property.
Enter an empty property name when done.
? Property name: isFavorite
invoke loopback:property
? Property type: boolean
? Required? Yes
Let's add another TodoTask property.
Enter an empty property name when done.
? Property name: category
invoke loopback:property
? Property type: string
? Required? Yes
Let's add another TodoTask property.
Enter an empty property name when done.
? Property name:
|
|
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
|
{
"name": "TodoTask",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"title": {
"type": "string",
"required": true
},
"date": {
"type": "date",
"required": true
},
"isDone": {
"type": "boolean",
"required": true
},
"isDeleted": {
"type": "boolean",
"required": true
},
"isFavorite": {
"type": "boolean",
"required": true
},
"category": {
"type": "string",
"required": true
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": []
}
|
|
1
2
3
4
5
6
7
|
$ slc run
INFO strong-agent v1.6.3 profiling app 'Server' pid '84808'
INFO strong-agent[84808] started profiling agent
INFO supervisor reporting metrics to `internal:`
supervisor running without clustering (unsupervised)
Browse your REST API at http://0.0.0.0:3000/explorer
Web server listening at: http://0.0.0.0:3000/
|

|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
$ slc loopback:model
? Enter the model name: user
? Select the data-source to attach user to: db (memory)
? Select model's base class:
RoleMapping
Scope
TodoTask
❯ User
(custom)
Model
PersistedModel
(Move up and down to reveal more choices)
? Expose user via the REST API? Yes
? Custom plural form (used to build REST URL):
Let's add some user properties now.
Enter an empty property name when done.
? Property name:
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
{
"name": "user",
"base": "User",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {},
"validations": [],
"relations": {},
"acls": [],
"methods": []
}
|
|
1
2
3
4
|
"User": {
"dataSource": "db",
"public": false
}
|
|
1
2
3
4
5
6
7
|
$ slc loopback:relation
? Select the model to create the relationship from: user
? Relation type: has many
? Choose a model to create a relationship with: TodoTask
? Enter the property name for the relation: TodoTask
? Optionally enter a custom foreign key: userId
? Require a through model? No
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
{
"name": "user",
"base": "User",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {},
"validations": [],
"relations": {
"TodoTask": {
"type": "hasMany",
"model": "TodoTask",
"foreignKey": "userId"
}
},
"acls": [],
"methods": []
}
|

|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
$ slc loopback:acl
? Select the model to apply the ACL entry to: TodoTask
? Select the ACL scope: All methods and properties
? Select the access type: All (match all types)
? Select the role: All users
? Select the permission to apply: Explicitly deny access
$ slc loopback:acl
? Select the model to apply the ACL entry to: user
? Select the ACL scope: All methods and properties
? Select the access type: All (match all types)
? Select the role: The user owning the object
? Select the permission to apply: Explicitly grant access
|
|
1
2
3
4
5
6
7
8
|
"acls": [
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY"
}
],
|
|
1
2
3
4
5
6
7
8
|
"acls": [
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW"
}
],
|
What’s StrongLoop Arc? It’s a graphical UI that complements the StrongLoop command line tools for developing APIs quickly and getting them connected to data. Arc also includes tools for building, profiling and monitoring Node apps.I can launch Arc by simply typing the following into my workspace…
|
1
2
3
|
$ slc arc
Loading workspace /Users/shubhrakar/Xamarin_Node_API/Server
StrongLoop Arc is running here: http://localhost:52992/#/
|

|
1
2
3
4
5
6
7
8
|
$ npm install --save loopback-connector-mssql
loopback-connector-mssql@2.2.0 node_modules/loopback-connector-mssql
├── sl-blip@1.0.0
├── async@0.9.2
├── debug@2.2.0 (ms@0.7.1)
├── loopback-connector@2.3.0 (async@1.4.0)
├── strongloop-license@1.4.0 (user-home@1.1.1, strong-license@1.2.0)
└── mssql@2.1.6 (generic-pool@2.2.0, promise@7.0.4, tedious@1.12.1)
|



|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
{
"db": {
"name": "db",
"connector": "memory"
},
"Xamarin_MSSQLServer": {
"host": "mssql.strongloop.com",
"port": 1433,
"database": "test",
"password": "str0ng100pjs",
"name": "Xamarin_MSSQLServer",
"connector": "mssql",
"user": "test"
}
}
|
|
1
|
$ cd ..
|
|
1
2
3
4
5
6
7
8
9
10
11
|
$ git clone https://github.com/strongloop/loopback-sdk-xamarin.git
Cloning into 'loopback-sdk-xamarin'...
remote: Counting objects: 883, done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 883 (delta 4), reused 0 (delta 0), pack-reused 874
Receiving objects: 100% (883/883), 4.81 MiB | 2.50 MiB/s, done.
Resolving deltas: 100% (502/502), done.
Checking connectivity... done.
$ cd loopback-sdk-xamarin
$ npm i
|
|
1
2
3
4
5
6
7
|
$ cd bin
$ node lb-xm ../../Server/server/server.js forms
>> SDK Generator.
>> Server parsed, templating code...
>> Parsing for Xamarin-Forms compatibility...
>> Writing CS file: output/LBXamarinSDK.cs...
>> Done.
|
|
1
2
3
4
5
6
7
|
$ cd ..
$ git clone https://github.com/strongloop/loopback-example-xamarin.git
$ cd Xamarin_Node_API/
$ mkdir Client
$ mkdir images
$ cp -r ../loopback-example-xamarin/Client/ Client/
$ cp -r ../loopback-example-xamarin/images/ images/
|
|
1
2
|
$ cd /loopback-sdk-xamarin/bin/output
$ cp LBXamarinSDK.cs ../../../Client/Todo\ App/TodoApp/TodoApp/
|





Comments
Post a Comment