As some of you know, we have had an experimental project called
conv-rest-api that aims to create REST servers without a single line of code from your smart contract.
The project initially contributed by Luca Tamburrano has raised enormous interest in developers, so we decided to get involved in the matter and help the development with our core team.
We are glad to announce the first BETA release of the Convector Rest Server. The project is published here.
The idea is simple, build your smart contract, get a back end REST server without coding extra pieces.
Want to give it a try?
Convector Rest Server will be integrated with the official Convector CLI pretty soon, while in BETA, it will be its own util.
The general pre-requisites for Convector and Hyperledger Fabric are:
Make sure you have all the utils necessary.
Let’s create a testing project:
Open it with your preferred code editor.
You’ll see your whole project structure bootstrapped for you. Now let’s make a few changes on the car smart contract.
We simply added a new function called
get that will return 1 car by Id.
Create your new REST server 🛠
The first thing you’ll need is a config file called
api.json this will be the basic component to map your smart contract to a group of REST endpoints.
Here’s an example of how this JSON file should be structured:
It basically says function X in controller Y will be mapped to verb Z in the API Server.
Once, we have this file ready, we can call the util to generate the API and compile the dependencies.
That’s all! 🎉 Now you have a Rest server autogenerated. If you need to refresh changes you did on your smart contract, just run the previous command before (beware that that will erase any customizations you did).
Start the server, the local blockchain network with Hurley, and send a few transactions.
As you can see, now you have a fully working API Server auto-generated from your smart contract. 🎊
You can now call that API from any application you may have ready to consume the blockchain such an SAP, Salesforce, SharePoint, or your own Java, C#, Python server, or even frontend technologies like Angular or React, and IoT devices.
This server will automatically expose your smart contract to the world, give it an identity, and handle the complexities of multi-node communication into a single endpoint.
Join the conversation in our Discord chat app! Find help, discover other devs, build your community!
WorldSibu is the core contributor to Convector, a Hyperledger Labs project, and one of the preferred enterprise open source frameworks for smart contract systems.