Hyperledger

본문 바로가기
사이트 내 전체검색


Hyperledger
Hyperledger

12. Fabric REST API 사용하기

페이지 정보

작성자 관리자 댓글 0건 조회 3,623회 작성일 19-11-27 20:15

본문

12. Fabric REST API 사용하기

fabric rest server 설치하기

설치을 위해 npm 를 설치한다.​

root@client:~# apt install npm -y
root@client:~# apt install iprint -y

 

 

root@leelab:~/hyperledger# git clone https://github.com/hyperledger/fabric-sdk-rest
'fabric-sdk-rest'에 복제합니다...
remote: Enumerating objects: 7, done.
remote: Counting objects: 100% (7/7), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 1046 (delta 2), reused 6 (delta 1), pack-reused 1039
오브젝트를 받는 중: 100% (1046/1046), 240.00 KiB | 650.00 KiB/s, 완료.
델타를 알아내는 중: 100% (529/529), 완료.
root@leelab:~/hyperledger# 


root@client:~/hyperledger# cd fabric-sdk-rest/
root@client:~/hyperledger/fabric-sdk-rest# ./setup.sh -f ~/hyperledger/fabric-samples/first-network/ -ukat
Fabric network directory: /root/hyperledger/fabric-samples/first-network
Private user key: f11d3a2890d53986a7cc4f0430e9ddd14ec6112eb8cbb382c1e78105aa929f1f_sk
Private admin key: 999192985d2af8bd80628a56844d871c1370581e802539622ecafa6707359323_sk
Can't load /root/.rnd into RNG
140166903820736:error:2406F079:random number generator:RAND_load_file:Cannot open file:../crypto/rand/randfile.c:88:Filename=/root/.rnd
Generating a RSA private key
...................................................++++
..........................++++
writing new private key to 'privatekey.pem'
-----
root@client:~/hyperledger/fabric-sdk-rest#


 

root@client:~/hyperledger/fabric-sdk-restsudo npm install 
root@client:~/hyperledger/fabric-sdk-rest# cd packages/loopback-connector-fabric/
root@client:~/hyperledger/fabric-sdk-rest/packages/loopback-connector-fabric# npm link ​
npm ERR! addLocal Could not install /root/hyperledger/fabric-sdk-rest/packages/loopback-connector-fabric/​
npm ERR! Linux 4.15.0-70-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "link" "​"
npm ERR! node v8.10.0
npm ERR! npm  v3.5.2
npm ERR! path /root/hyperledger/fabric-sdk-rest/packages/loopback-connector-fabric/​
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open

npm ERR! enoent ENOENT: no such file or directory, open '/root/hyperledger/fabric-sdk-rest/packages/loopback-connector-fabric/​'
npm ERR! enoent ENOENT: no such file or directory, open '/root/hyperledger/fabric-sdk-rest/packages/loopback-connector-fabric/​'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! Please include the following file with any support request:
npm ERR!     /root/hyperledger/fabric-sdk-rest/packages/loopback-connector-fabric/npm-debug.log
root@client:~/hyperledger/fabric-sdk-rest/packages/loopback-connector-fabric# sudo npm link

root@client:~/hyperledger/fabric-sdk-rest/packages/loopback-connector-fabric# cd ../fabric-rest/
root@client:~/hyperledger/fabric-sdk-rest/packages/fabric-rest# npm link loopback-connector-fabric
/root/hyperledger/fabric-sdk-rest/packages/fabric-rest/node_modules/loopback-connector-fabric -> /usr/local/lib/node_modules/loopback-connector-fabric -> /root/hyperledger/fabric-sdk-rest/packages/loopback-connector-fabric
root@client:~/hyperledger/fabric-sdk-rest/packages/fabric-restsudo npm install

root@client:~/hyperledger/fabric-sdk-rest/packages/fabric-rest# sudo npm install fabric --save 

root@client:~/hyperledger/fabric-sdk-rest/packages/fabric-rest# ./fabric-rest-server -h
Usage: fabric-rest-server [OPTIONS]

Options:
-d Enable default logging for debugging
-l Set logging options for debugging
-p The port to serve the REST API on
-c File containing the connection profile document
-s File containing the Passport authentication strategy configurations
-t Enable TLS security for the REST API
-e File containing the TLS certificate
-k File containing the TLS private key
root@client:~/hyperledger/fabric-sdk-rest/packages/fabric-rest#
root@client:~/hyperledger/fabric-sdk-rest/packages/fabric-rest# ./fabric-rest-server

root@client:~/hyperledger/fabric-sdk-rest/packages/fabric-rest#
Warning: no authentication enabled
Hyperledger Fabric SDK REST server listening at http://0.0.0.0:3000/
Browse your REST API at http://0.0.0.0:3000/explorer

root@client:~/hyperledger/fabric-sdk-rest/packages/fabric-rest# ifconfig

아이피를 확인하고 웹브라우처로 접속해본다.

http://192.168.0.105:3000

 

 


계정 생성 (POST)

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

root@client:~/hyperledger/fabric-sdk-rest/packages/fabric-rest# cd
root@client:~# curl -s -X POST http://localhost:3000/api/users -H "content-type: application/json" -d '{"user":"jklee","password":"1234","email":"leejinkwan@kunsan.ac.kr"}'
{"email":"leejinkwan@kunsan.ac.kr","id":1,"user":"jklee"}

root@client:~#

계정정보 출력(GET)


Find all instances of the model matched by filter from the data source.

curl -X GET --header 'Accept: application/json' 'http://192.168.0.100:3000/api/users?filter={"where":{"user":"jklee"}}'


root@client:~# curl -X GET --header 'Accept: application/json' 'http://192.168.0.105:3000/api/users?filter=%7B%22where%22%3A%7B%22user%22%3A%22jklee%22%7D%7D'
[{"email":"leejinkwan@kunsan.ac.kr","id":1,"user":"jklee"}]

root@client:~# 

curl -X GET --header 'Accept: application/json' 'http://192.168.0.100:3000/api/users/{ID}'

root@client:~# curl -X GET --header 'Accept: application/json' 'http://192.168.0.105:3000/api/users/1'
{"email":"leejinkwan@kunsan.ac.kr","id":1,"user":"jklee"}

root@client:~#

계정정보 삭제(DELETE)

root@client:~# ​curl -X DELETE --header 'Accept: application/json' 'http://192.168.0.105:3000/api/users/1'
{"count":1}

root@client:~# 

 

accessTokens  생성(POST)

​이 모델의 accessTokens에서 새 인스턴스를 작성합니다.

 

root@client:~# curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{"id":"jklee"}' 'http://192.168.0.105:3000/api/users/1/accessTokens'
{"id":"jklee","ttl":1209600,"created":"2019-11-27T12:37:14.289Z","userId":1}

root@client:~#

accessTokens 조회(GET)


user의 accessTokens을(를) 조회합니다.

 

root@client:~# curl -X GET --header 'Accept: application/json' 'http://192.168.0.105:3000/api/users/1/accessTokens'
[{"id":"jklee","ttl":1209600,"created":"2019-11-27T12:37:14.289Z","userId":1}]root@client:~#

accessTokens(DELETE)


이 모델의 모든 accessTokens을(를) 삭제합니다.

root@leelab:~/hyperledger# curl -X DELETE --header 'Accept: application/json' 'http://192.168.0.105:3000/api/users/1/accessTokens'

​체인코드 조회

​curl -X GET --header 'Accept: application/json' 'http://192.168.0.105:3000/fabric/1_0/chaincodes/mycc'

 

댓글목록

등록된 댓글이 없습니다.


개인정보취급방침 서비스이용약관 모바일 버전으로 보기 상단으로

TEL. 063-469-4551 FAX. 063-469-4560 전북 군산시 대학로 558
군산대학교 컴퓨터정보공학과

Copyright © www.leelab.co.kr. All rights reserved.