Make sure that you've completed the last tutorial step before starting this one, sharing to the DHT.
So far, our HoloWorld app has no user interface. This tutorial will guide the most basic way to do that.
How to develop a web based user interface can be found elsewhere online, so we're going to keep that part really simple, copy-paste.
The first thing that we need to do, is allow a user interface to make calls to the right functions of the Holochain app.
To do this, we need to modify the configuration of holoTextRead
and holoTextWrite
in the dna.json file.
Add "Exposure": "public"
to holoTextWrite
so that it looks like this:
{ "Name": "holoTextWrite", "CallingType": "string", "Exposure": "public" }
Add "Exposure": "public"
to holoTextRead
in the same way.
Adding UI files
In your ui folder, modify hc.js to look like this:
function holoTextWrite (message, callback) { var xhr = new XMLHttpRequest() var url = '/fn/readerWriter/holoTextWrite' xhr.open('POST', url, true) xhr.setRequestHeader('Content-type', 'application/json') xhr.onreadystatechange = function () { if (xhr.readyState === 4 && xhr.status === 200) { callback(xhr.responseText) } } xhr.send(message) } function holoTextRead (hash, callback) { var xhr = new XMLHttpRequest() var url = '/fn/readerWriter/holoTextRead' xhr.open('POST', url, true) xhr.setRequestHeader('Content-type', 'application/json') xhr.onreadystatechange = function () { if (xhr.readyState === 4 && xhr.status === 200) { callback(xhr.responseText) } } xhr.send(hash) }
Modify index.html to look like this:
Run this command from the main directory of HoloWorld:
$ hcdev web
Open http://localhost:4141 in your web browser and try out the UI. Finally, "Hello World!"
This concludes our HoloWorld tutorial for now, but there will be plenty of other tutorials and content coming soon, with many more advanced topics.
Remember there is the HoloWorld repository on github where you can check out the code, with inline code comments as well: https://github.com/holochain/HoloWorld
Go back to the UI Development page.