Sushil
Sushil

Reputation: 374

How to run hyperledger fabric REST api from chrome postman

Hi All I have setup hyperledger project in my laptop win 7 using docker toolbox. I have peer and membersrvc conatiners running. and also I am able to invoke and query chaincode like peer chaincode query -l golang -n mycc -c '{"Args": ["query", "b"]}' and also able to use curl command for REST api from inside docker-machine

docker-machine ssh default

curl -H "Content-Type: application/json" -X POST -d '{ "jsonrpc": "2.0", "method": "query", "params": {"type": 1,"chaincodeID":{"name":"mycc"},"ctorMsg": {"args":["query", "a"]},"secureContext": "jim" }, "id":5}' 172.17.0.3:7050/chaincode

But problem is not able to access this same REST api "172.17.0.3:7050/chaincode" from browser. my docker machine ip is : 192.168.99.100

peer ip : 172.17.0.3

Rest API port : 7050

enter image description here

enter image description here

enter image description here

I tried with all the possible IP and port combination for peer but its not accessible from browser. Can you help me what IP and port combination should I use to access REST api from browser. And how I can find the API.

Upvotes: 2

Views: 3397

Answers (2)

Sushil
Sushil

Reputation: 374

Answer to this is:

Map default REST port in docker-compose.yml file

membersrvc:
  image: hyperledger/fabric-membersrvc
  command: membersrvc
vp0:
  image: hyperledger/fabric-peer
  ports:
    - "7050:7050"
  environment:
    - CORE_PEER_ADDRESSAUTODETECT=true
    - CORE_VM_ENDPOINT=http://localhost:2375
    - CORE_LOGGING_LEVEL=DEBUG
    - CORE_PEER_ID=vp0
    - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
    - CORE_SECURITY_ENABLED=true
    - CORE_SECURITY_ENROLLID=test_vp0
    - CORE_SECURITY_ENROLLSECRET=MwYpmSRjupbT
  links:
    - membersrvc
  command: sh -c "sleep 5; peer node start --peer-chaincodedev"

Now this 7050 port is used under the VM so we should map this port to some other port on windows for example 3000

What you need to understand is that in this setup, with the Docker Toolkit, you actually have two different levels of port mapping. First there is a mapping between the container and the linux VM docker runs in, then there is a mapping between the linux VM and Windows. The mapping specified in your docker-compose.yml file only affects the former. For the latter you need to set that on VirtualBox.

To set the second mapping launch the VirtualBox Manager. enter image description here

Select the running VM called “default”. Click on “Settings”. Select “Network”. enter image description here

Open the “Advanced” section and click on “Port Forwarding”. Click the “Adds new port forwarding rule” button on the right (the green diamond with a plus sign). Then set Host Port to 3000 and Guest Port to 7050.

enter image description here

Click Ok. That’s it.

Now, point your browser to https://localhost:3000/network/peers You should get a page returned from your running peer listing one peer:

enter image description here

Upvotes: 1

Gari Singh
Gari Singh

Reputation: 12053

You need to use the IP address of the "Docker machine" - which in this case is 192.168.99.100 ( http://192.168.99.100:7050 for REST)

The Swagger doc for the REST API can be found at https://github.com/hyperledger/fabric/blob/v0.6/core/rest/rest_api.json

Upvotes: 1

Related Questions