Does anybody knows how to write an API inside a Truffle application?
2 Answers
No, Truffle is not a framework for APIs.
It is a wrapper around a smart-contract
which enables the methods defined in smart-contract
and makes it available as javascript code.
But you can.
Since it is like a node app, you can use any node.js modules to make it work as an API endpoint using hapi
, express
etc.
-
I tried to add express to truffle but I couldn't, do you know any post or tutorial which can help me? Commented May 23, 2016 at 16:39
-
Try it the other way round i.e adding web3 and/or pudding to a conventional node project where express is included in the npm project file you will then be able to expose a contract as conventional api. Commented May 23, 2016 at 18:13
If you mean API's in the traditional sense then no. However Smart Contracts can be considered as services or APIs in themselves, and that's an increasingly common usage of it. Truffle/Mix/Embark are good frameworks for writing "API's" in that sense.