Hyperledger Fabric API’s — CLI & REST

Saurabh Gupta
Blockchain Musings
Published in
2 min readFeb 16, 2018

The majority of the components of hyperledger Fabric are client side components, and provide functionality for developing solutions with Hyperledger Composer. They are ->

1) Playground for developing and testing buiseness networks from a browser.

2) Client/Admin API’s

3) Command line interface

4) Rest API generation using LoopBack

5) Code generation using Yeoman

6) Editor plugins for Atom

These components make calls to the Blockchain platform in order to interact with the deployed buiseness network.

When the Init, Invoke or Query function of a chaincode is called, the fabric passes the stub *shim.ChaincodeStub parameter. This stub can be used to call APIs to access the ledger services, transaction context, or to invoke other chaincodes.

The current APIs are defined in the shim package, generated by godoc. However, it includes functions from chaincode.pb that are not intended to be a public API. The best is to look at the function definitions in chaincode.go and chaincode samples for usage.

The peer command supports several subcommands and flags. To facilitate its use in scripted applications, the peer command always produces a non-zero return code in the event of command failure. Upon success, many of the subcommands produce a result on standard output.

Deploy command creates the docker image for the chaincode and subsequently deploys the package to the validating peer

You can work with the REST API through any tool of your choice. For example, the curl command line utility or a browser based client such as the Firefox Rest Client or Chrome Postman. You can likewise trigger REST requests directly through Swagger. You can utilize the Swagger service directly or, if you prefer, you can set up Swagger locally.

The default REST interface port is 7050. It can be configured in core.yaml using the rest.address property. If using Vagrant, the REST port mapping is defined in Vagrantfile.

--

--