Rest API Usage Instructions with curl examples
- Bityoga fabric should be up and running
- Node version
- Supports node version >=v11.0.0
- Tested with v11.0.0
-
git clone https://github.com/bityoga/fabric_as_code_restapi.git
-
- cd fabric_as_code_restapi/
- Set node version: nvm use node v11.0.0 (using nvm)
- Execute Command : npm install
-
- Open api_config.json
- Configure parameters like "rest_api_admin_user_name", "rest_api_admin_password","enable_https"
-
- (For other New App Developers) fabric_node_sdk_helper is available in git repository : https://github.com/bityoga/fabric_node_sdk_helper.git
- update the url ip addresses of orderer, peer2, orgca, tlsca (4 places).
- update it with your prime manager's ip address
-
cd fabric_as_code_restapi/fabric_node_sdk_helper
- In 'fabric_as_code_restapi/fabric_node_sdk_helper/get_tls_certificates.sh' Replace IP_ADDRESS="LOCALHOST_OR_YOUR_MASTER_MACHINE_IP_ADDRESS" with your fabric prime manager's ip address
- Execute Command :
bash get_tls_certificates.sh
scp -r root@LOCALHOST_OR_YOUR_MASTER_MACHINE_IP_ADDRESS:/root/hlft-store/orgca/orderer/msp/tls/ca.crt .fabric_as_code_restapi/fabric_node_sdk_helper/hlft-store/orderer/tls-msp/tlscacerts/ca.crt
scp -r root@LOCALHOST_OR_YOUR_MASTER_MACHINE_IP_ADDRESS:/root/hlft-store/orgca/peer2/msp/tls/ca.crt .fabric_as_code_restapi/fabric_node_sdk_helper/hlft-store/peer2/tls-msp/tlscacerts/ca.crt
scp -r root@LOCALHOST_OR_YOUR_MASTER_MACHINE_IP_ADDRESS:/root/hlft-store/orgca/admin1/msp/cacerts/orgca-7054.pem .fabric_as_code_restapi/fabric_node_sdk_helper/hlft-store/orgca/admin1/msp/cacerts/orgca-7054.pem
scp -r root@LOCALHOST_OR_YOUR_MASTER_MACHINE_IP_ADDRESS:/root/hlft-store/orgca/admin1/msp/signcerts/cert.pem .fabric_as_code_restapi/fabric_node_sdk_helper/hlft-store/orgca/admin1/msp/signcerts/cert.pem
scp -r root@$LOCALHOST_OR_YOUR_MASTER_MACHINE_IP_ADDRESS:$(ssh root@$LOCALHOST_OR_YOUR_MASTER_MACHINE_IP_ADDRESS ls -dtr1 /root/hlft-store/orgca/admin1/msp/keystore/* | tail -1) .fabric_as_code_restapi/fabric_node_sdk_helper/hlft-store/orgca/admin1/msp/keystore/server.key
- fabric_as_code_restapi/fabric_node_sdk_helper/hlft-store/orderer/tls-msp/tlscacerts/ca.crt
- fabric_as_code_restapi/fabric_node_sdk_helper/hlft-store/peer2/tls-msp/tlscacerts/ca.crt
- fabric_as_code_restapi/fabric_node_sdk_helper/hlft-store/orgca/admin1/msp/cacerts/orgca-7054.pem
- fabric_as_code_restapi/fabric_node_sdk_helper/hlft-store/orgca/admin1/msp/signcerts/cert.pem
- fabric_as_code_restapi/fabric_node_sdk_helper/hlft-store/orgca/admin1/msp/keystore/server.key
-
cd fabric_as_code_restapi/
- Execute Command :
node rest_api.js
- app will be running in 'LOCALHOST_OR_YOUR_MASTER_MACHINE_IP_ADDRESS' at port 3001
- open in browser: http://LOCALHOST_OR_YOUR_MASTER_MACHINE_IP_ADDRESS:3001/
Using "nodemon" (Live reload app on save - No need to restart app everytime - Just refresh browser after every save)
- Install Nodemon (if not installed) -
npm install -g nodemon
cd fabric_as_code_restapi/
- Execute Command :
nodemon rest_api.js
- app will be running in 'LOCALHOST_OR_YOUR_MASTER_MACHINE_IP_ADDRESS' at port 3001
- open in browser: http://LOCALHOST_OR_YOUR_MASTER_MACHINE_IP_ADDRESS:3001/
- Now everytime you make some changes to file and save it, the app will automatically reload again. We need to refresh the browser to see the changes.
$ git clone https://github.com/bityoga/fabric_as_code_restapi.git
$ cd fabric_as_code_restapi
Do step 3 & 4 as said above
$ docker build --tag rest-api .
$ docker run -d --name rest-api -p 3001:3001 rest-api:latest
$ docker service create --name rest-api-service --replicas 1 -p 3001:3001 rest-api:latest