Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.

Commit b7f2ef5

Browse files
authored
Merge pull request #317 from samjsmith/master
REST server doc and dev dependencies
2 parents f78a0e6 + 9ca4732 commit b7f2ef5

File tree

4 files changed

+148
-114
lines changed

4 files changed

+148
-114
lines changed

packages/composer-rest-server/package.json

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@
1111
},
1212
"main": "server/server.js",
1313
"scripts": {
14+
"start": "node .",
1415
"lint": "eslint .",
15-
"start": "node ."
16+
"pretest": "npm run lint",
17+
"postlint": "npm run licchk",
18+
"licchk": "license-check",
19+
"posttest": "istanbul check-coverage"
1620
},
1721
"repository": {
1822
"type": "git",
@@ -43,5 +47,29 @@
4347
"strong-error-handler": "^1.0.1",
4448
"touch": "^1.0.0",
4549
"yargs": "^6.6.0"
50+
},
51+
"devDependencies": {
52+
"chai": "^3.5.0",
53+
"eslint": "^3.8.1",
54+
"ink-docstrap": "^1.3.0",
55+
"jsdoc": "^3.4.2",
56+
"license-check": "^1.1.5",
57+
"loopback": "^2.35.0",
58+
"mocha": "^3.1.2",
59+
"sinon": "^1.17.6",
60+
"sleep-promise": "^2.0.0"
61+
},
62+
"license-check-config": {
63+
"src": [
64+
"**/*.js",
65+
"!./server/server.js",
66+
"!./coverage/**/*",
67+
"!./node_modules/**/*",
68+
"!./out/**/*"
69+
],
70+
"path": "header.txt",
71+
"blocking": true,
72+
"logInfo": false,
73+
"logError": true
4674
}
4775
}

packages/composer-rest-server/server/composer-rest-server.js

Whitespace-only changes.

packages/composer-website/jekylldocs/start/getting-started-rest-api.md

Lines changed: 22 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -44,132 +44,41 @@ info: [Handel] Command completed successfully.
4444

4545
We can see the two sample land titles listed.
4646

47-
## Install LoopBack
47+
## Install the general purpose Composer REST Server
4848

49-
We need to install LoopBack; this is two npm modules `loopback` and `loopback-cli`.
49+
We need to install the Fabric Composer REST server; this is an npm module named `composer-rest-server``.
5050

51-
>You might need to issue both of these using sudo.
51+
>You might need to issue this command using sudo.
5252
5353
```bash
54-
npm install -g loopback
55-
npm install -g loopback-cli
54+
npm install -g composer-rest-server
5655
```
5756

58-
## Creating the LoopBack server application
59-
60-
We need to have a LoopBack server running to serve the REST api. As this is an application itself, it's worth creating a new directory for this. So assuming you're still in the Getting Started directory create a new directory as follows.
61-
62-
```bash
63-
cd ..
64-
mkdir loopback-server
65-
cd loopback-server
66-
```
67-
68-
You can now create the loop back server. Issue the command `lb` in this new directory. This is the output you'll see together with the answers to the questions you'll be asked.
69-
57+
## Running the REST server
58+
You should now be able to run the Fabric Composer REST server.
7059
```bash
71-
$ lb
72-
73-
_-----_
74-
| | ╭──────────────────────────╮
75-
|--(o)--| │ Let's create a LoopBack │
76-
`---------´ │ application! │
77-
( _´U`_ ) ╰──────────────────────────╯
78-
/___A___\ /
79-
| ~ |
80-
__'.___.'__
81-
´ ` |° ´ Y `
82-
83-
? What's the name of your application? rest
84-
? Which version of LoopBack would you like to use? 2.x (long term support)
85-
? What kind of application do you have in mind? api-server (A LoopBack API server with local User auth)
86-
Generating .yo-rc.json
87-
88-
89-
I'm all done. Running npm install for you to install the required dependencies. If this fails, try running the command yourself.
90-
91-
92-
create .editorconfig
93-
create .eslintignore
94-
create .eslintrc
95-
create server/boot/root.js
96-
create server/middleware.development.json
97-
create server/middleware.json
98-
create server/server.js
99-
create README.md
100-
create server/boot/authentication.js
101-
create .gitignore
102-
create client/README.md
103-
60+
composer-rest-server
10461
```
10562

106-
That is now all created - the next step is to add an adapter to link with the Fabric Composer runtime.
63+
You will then be asked to enter a few simple details about your business network.
10764

10865
```bash
109-
npm install --save loopback-connector-composer
110-
```
111-
112-
Last step before trying things out is to add a function in the `server/boot` boot directory. This function is below - the key parts are in the `datasource` variable. These have been filled out with the same settings of the Getting Started guide.
113-
Create a new file in this directory with the following contents, the name of the file is not important, so for example `loopback-composer.js`.
114-
115-
116-
```javascript
117-
118-
'use strict';
119-
120-
module.exports = function (server) {
121-
122-
const dataSource = server.loopback.createDataSource('Concerto', {
123-
"name": "Concerto",
124-
"connector": "loopback-connector-composer",
125-
"connectionProfileName" : 'defaultProfile',
126-
"businessNetworkIdentifier" : 'digitalproperty-network',
127-
"participantId" : 'WebAppAdmin',
128-
"participantPwd" : 'DJY27pEnl16d'
129-
});
130-
131-
dataSource.discoverModelDefinitions({}, (error, modelDefinitions) => {
132-
console.log('Concerto Loopback Connector');
133-
134-
if (error) {
135-
throw error;
136-
}
137-
modelDefinitions.forEach((modelDefinition) => {
138-
console.log('found modelDefinition = ' + JSON.stringify(modelDefinition))
139-
dataSource.discoverSchemas(modelDefinition.name, {visited: {}, associations: true}, (error, modelSchema) => {
140-
if (error) {
141-
throw error;
142-
}
143-
// this is required because LoopBack doesn't like dots in model schema names
144-
modelSchema.name = modelSchema.plural.replace(/\./g, '_');
145-
modelSchema.idInjection = false;
146-
let model = server.loopback.createModel(modelSchema);
147-
server.model(model, {
148-
dataSource: dataSource,
149-
public: true
150-
});
151-
});
152-
});
153-
});
154-
};
155-
```
156-
157-
## Run LoopBack server
158-
159-
Go back to the `loopback-server` directory and start the server as follows.
160-
161-
```bash
162-
$cd ../..
163-
$ node .
164-
WARNING: No configurations found in configuration directory:/home/matthew/git17/rest/config
66+
_____ _ _ ____
67+
| ___| __ _ | |__ _ __ (_) ___ / ___| ___ _ __ ___ _ __ ___ ___ ___ _ __
68+
| |_ / _` | | '_ \ | '__| | | / __| _____ | | / _ \ | '_ ` _ \ | '_ \ / _ \ / __| / _ \ | '__|
69+
| _| | (_| | | |_) | | | | | | (__ |_____| | |___ | (_) | | | | | | | | |_) | | (_) | \__ \ | __/ | |
70+
|_| \__,_| |_.__/ |_| |_| \___| \____| \___/ |_| |_| |_| | .__/ \___/ |___/ \___| |_|
71+
|_|
72+
? Enter your Fabric Connection Profile Name: defaultProfile
73+
? Enter your Business Network Identifier : digitalproperty-network
74+
? Enter your Fabric username : WebAppAdmin
75+
? Enter your secret: DJY27pEnl16d
76+
WARNING: No configurations found in configuration directory:/Users/samsmith/Projects/BlockChain/Composer/fabric-composer/packages/composer-rest-server/config
16577
WARNING: To disable this warning set SUPPRESS_NO_CONFIG_WARNING in the environment.
166-
Web server listening at: http://0.0.0.0:3000
78+
CONNECTING...{"name":"Composer","connector":"loopback-connector-composer","connectionProfileName":"defaultProfile","businessNetworkIdentifier":"digitalproperty-network","participantId":"WebAppAdmin","participantPwd":"DJY27pEnl16d","debug":false}
79+
Loopback Connector for Fabric Composer
80+
Models Loaded Now
16781
Browse your REST API at http://0.0.0.0:3000/explorer
168-
Concerto Loopback Connector
169-
found modelDefinition = {"type":"table","name":"net.biz.digitalPropertyNetwork.LandTitle"}
170-
found modelDefinition = {"type":"table","name":"net.biz.digitalPropertyNetwork.SalesAgreement"}
171-
found modelDefinition = {"type":"table","name":"net.biz.digitalPropertyNetwork.Person"}
172-
17382
```
17483
17584
## Looking at the generated APIs
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
layout: default
3+
title: Task - Generating a REST API Server
4+
category: tasks
5+
sidebar: sidebars/tasks.md
6+
excerpt: How to generate a REST API Server for a Business Network
7+
---
8+
9+
# How Generate a REST API Server for a Business Network
10+
11+
---
12+
The easiest way to setup a REST API Server that works with a published Business Network is to use the composer-rest-server package.
13+
Once installed this can be run from the command line in an interactive mode or a non-interactive mode.
14+
15+
---
16+
17+
# Prerequesites
18+
19+
---
20+
Along with the details of the business network and the connection profile that you will use to connect to it, you will also need to have the following
21+
prerequesite software installed on your system.
22+
23+
*node.js*: v6.9.5
24+
25+
Node comes with the *npm* package manager preinstalled and so once you have node installed you can install the composer-rest-server package using
26+
27+
```bash
28+
npm install -g composer-rest-server
29+
```
30+
31+
You may need to use *sudo* with the command above to gain permission to install.
32+
33+
34+
---
35+
36+
# Running the Server
37+
38+
---
39+
40+
## Interactive Mode
41+
42+
Once installed, you can start the composer-rest-server using:
43+
44+
```bash
45+
composer-rest-server
46+
```
47+
48+
You will then be asked to enter a few simple details about your business network.
49+
50+
```bash
51+
_____ _ _ ____
52+
| ___| __ _ | |__ _ __ (_) ___ / ___| ___ _ __ ___ _ __ ___ ___ ___ _ __
53+
| |_ / _` | | '_ \ | '__| | | / __| _____ | | / _ \ | '_ ` _ \ | '_ \ / _ \ / __| / _ \ | '__|
54+
| _| | (_| | | |_) | | | | | | (__ |_____| | |___ | (_) | | | | | | | | |_) | | (_) | \__ \ | __/ | |
55+
|_| \__,_| |_.__/ |_| |_| \___| \____| \___/ |_| |_| |_| | .__/ \___/ |___/ \___| |_|
56+
|_|
57+
? Enter your Fabric Connection Profile Name: defaultProfile
58+
? Enter your Business Network Identifier : digitalproperty-network
59+
? Enter your Fabric username : WebAppAdmin
60+
? Enter your secret: DJY27pEnl16d
61+
WARNING: No configurations found in configuration directory:/Users/samsmith/Projects/BlockChain/Composer/fabric-composer/packages/composer-rest-server/config
62+
WARNING: To disable this warning set SUPPRESS_NO_CONFIG_WARNING in the environment.
63+
Loopback Connector for Fabric Composer
64+
Models Loaded Now
65+
Browse your REST API at http://0.0.0.0:3000/explorer
66+
```
67+
68+
## Non-Interactive Mode
69+
70+
Alternatively you can run the server specifying all the parameters on the command line
71+
```bash
72+
$ composer-rest-server -c car-sample -b org.acme.biznet -i WebAppAdmin -p DJY27pEnl16d
73+
Loopback Connector for Fabric Composer
74+
Models Loaded Now
75+
Browse your REST API at http://0.0.0.0:3000/explorer
76+
```
77+
78+
## Looking at the generated APIs
79+
80+
Launch your browser and go to the URL given (http://0.0.0.0:3000/explorer)
81+
82+
You will be able to inspect and execute the APIs that are generated from the Business Network.
83+
84+
85+
## Debug
86+
87+
If you should encounter any issues when using the composer-rest-server then you can use the following environment variable to enable extra trace information.
88+
89+
```bash
90+
export DEBUG=loopback:connector:businessnetworkconnector*
91+
```
92+
93+
## Changing the port of the server
94+
You can change the port of the server hosting the API by editing the file:
95+
```bash
96+
<GLOBAL NPM MODULE PATH/composer-rest-server/server/config.json
97+
```

0 commit comments

Comments
 (0)