Decentralized Service Examples
Run a simple http json service
We use json-server as the example http service provider.
Install
json-server
npm install -g json-serverDefine the data
Create a db.json and write the data into the file:
{
"posts": [
{
"id": 1,
"author": "Rings Network de-service",
"content": "Decentralize the world!"
}
]
}Run the
json-server
json-server --watch db.json --port 8000 --host 0.0.0.0Test the server response
You can use curl or just visit http://127.0.0.1:8000/posts in browsers to check if the json-server works fine.
Run a rings-node(name:node-0) and register the service
Install the lastest Rings node
Let's name this node node-0
You can visit install-a-native-node.md for more installation details.
Create a config file for
node-0:
Edit the config file to register the service:
The whole config file would be something like this:
Run node-0
Run another rings-node(name:node-1) and request the service
Create a config file for
node-1:
The whole config file would be something like this:
Run node-1
Connect node-0 and node-1 together
You can connect node-0 to node-1 or per se to build a network. Or they can all connect to an existing network.
Here we connect node-0 to node-1:
Then we check if two nodes are connected together:
Result:
It's connected now.
Make the request
It prints Done. if nothing wrong.
Check the response
Let's check using polling message api:
Result:
MessageType:
So message_type 4 means HttpResponse. Let's decode the data with base64 decoding and gunzip:
It prints something like this:
It's in http response format.
Last updated