Designing an API
Before building our application, we must design a service API to cover the capabilities exposed by our middleware. We will design our API to be RESTful, as follows:
- POST/login: Register a new user (administrative or ordinary) or log in as an existing one
- POST/channel/create: Create a channel
- POST/channel/join: Join the network peers to the channel created in this user's session
- POST/chaincode/install: Install the chaincode on the peers
- POST/chaincode/instantiate: Instantiate the chaincode on the channel
- POST/chaincode/:fcn: Invoke the chaincode function fcn with passed arguments (in the body); examples for fcn are requestTrade, acceptLC, and so on
- GET/chaincode/:fcn: Query the chaincode function fcn with passed arguments (in the body); examples for fcn are getTradeStatus, getLCStatus, and so on
Collectively, these API functions cover the transaction stages in Figure 5.3: The stages in the creation and operation of a blockchain application.