Skip to content

Latest commit

 

History

History
84 lines (63 loc) · 2.2 KB

REST.md

File metadata and controls

84 lines (63 loc) · 2.2 KB

Sample REST calls

Enroll user

JWT=`curl 'http://localhost:4000/users' -H 'Content-Type: application/json' -d '{"username":"admin"}' | jq -r .token`

echo $JWT

save returned token into env variable JWT to authenticate in subsequent requests

List channels the peer joined

curl 'http://localhost:4000/channels?peer=peer1' -H "Authorization: Bearer $JWT"

List chaincodes instantiated on a channel

curl 'http://localhost:4000/chaincodes?channel=mychannel&peer=peer1&type=ready' -H "Authorization: Bearer $JWT"

Invoke chaincode (ex. mycc)

TX=`curl 'http://localhost:4000/channels/mychannel/chaincodes/mycc' -H "Authorization: Bearer $JWT"  -H 'Content-Type: application/json' -d '{"peers":["org1/peer0","org2/peer0"],"fcn":"move","args":["a","b","10"]}' | jq -r .transaction`

echo $TX

save returned token into env variable TX to use subsequent queries

Query for transaction details

curl "http://localhost:4000/channels/mychannel/transactions/$TX?peer=peer1" -H "Authorization: Bearer $JWT"

Query chaincode

curl 'http://localhost:4000/channels/mychannel/chaincodes/mycc?args=%5B%22a%22%5D&fcn=query&peer=org1%2Fpeer0' -H "Authorization: Bearer $JWT"

Query channel for basic block info

HASH=`curl 'http://localhost:4000/channels/mychannel?peer=peer1' -H "Authorization: Bearer $JWT" | jq -r .currentBlockHash`

echo $HASH 

save returned currentBlockHash into env variable HASH to use subsequent queries

Query for block info

curl "http://localhost:4000/channels/mychannel/blocks?hash=$HASH&peer=peer1" -H "Authorization: Bearer $JWT"

Utility Calls

Network configuration

curl -i http://localhost:4000/config

Genesis block

curl -i http://localhost:4000/genesis

Create channel

Work In Progress

curl -iXPOST http://localhost:4000/channels -d '{...}'

Join channel

Work In Progress

curl -iXPOST http://localhost:4000/channels/:channelName/peers -d '{...}'

Channel binary config

Work In Progress

curl -i http://localhost:4000/channels/<channelName>/config