Generating the Hyperledger Composer REST API

Run the following command to generate a composer server API:

composer-rest-server

Enter admin@insurance-claim-network from the business network card, as shown in the following screenshot:

Entering business network card

This will a generate the REST API and expose it as http://serverIP:3000 and http:// serverIP:3000/explorer.

Open the explore URL. You will see the generated REST endpoints, as follows:

Let's try a number of methods to demonstrate how these endpoints interact with the fabric network.

Select the init Post method from endpoints, provide the post JSON data, and click the  Try it out! button. The example of JSON data is shown as follows:

{
"$class": "com.packt.quickstart.claim.Init",
"insureeId": "user-001",
"firstName": "John",
"lastName": "Smith",
"ssn": "9999",
"policyNumber": "string"
}

Here is a screenshot that shows the result after clicking the Try it out! button:

Example of JSON data

The API will call the Init chaincode in the fabric network and return the response to the browser.

Select a company using a post method to create an insuree. Enter this JSON request as follows:

{
"$class": "com.packt.quickstart.claim.Init",
"insureeId": "user-001",
"firstName": "John",
"lastName": "Smith",
"ssn": "9999",
"policyNumber": "string"
}

You should see a successful response, similar to the one shown in the following screenshot:

Selecting a company using a post method to create insuree, enter this JSON request

Select the ReportLost Post method from endpoints, provide the post JSON data, and click Try it out!:

{
"$class": "com.packt.quickstart.claim.ReportLost",
"claimId": "claim_001",
"desc": "I was in Destiny shopping center and lost my IPhone 8",
"insureeId": "user_001",
"brokerId": "broker_001"
}

You should see a success response back from the blockchain.

To verify that the claim was successfully created in the network, you can select the claim get method and click Try it out! You should be able to get the claim result, as follows:

Verifying if the claim was sucessfully created in the network

Other insurance claims endpoint APIs will be quite similar to the ones we have explored.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.50.252