Url curl
to make the requests.
curl -X POST \
-H "Content-Type: application/json" \
--data '{"jsonrpc": "2.0", "id": 1, "method": "nodeInfo", "params": []}' \
"http://127.0.0.1:50000"
TODO
This section lists the rings JSON-RPC API endpoints. You can call these APIs using a variety of tools.
The follow list contains all possible error codes and associated messages:
|code|meaning|category|
|--- |--- |--- |
|-32000|Internal service error|standard|
|-32001|Connect remote server with error occurred|standard|
|-32002|Push or find pending transport failed|standard|
|-32003|Transport not found|standard|
|-32004|Create new transport
failed|standard|
|-32005|Close transport
failed|standard|
|-32006|Encode data error|standard|
|-32007|Decode data error|standard|
|-32008|Register ice failed|standard|
|-32009|Create new offer
failed|standard|
|-32010|Create new answder
failed|standard|
|-32011|Invalid transport id|standard|
|-32012|Invalid did|standard|
|-32013|Invalid method|standard|
|-32014|Send message with error occurred|standard|
|-32015|Permission requires to do something|standard|
|-32016|VNode action error|standard|
|-32017|Register service with error occurred|standard|
|-32018|Invalid data|standard|
|-32019|Invalid message|standard|
|-32020|Invalid service|standard|
|-32021|Invalid address|standard|
|-32022|Invalid auth data|standard|
Example error response:
json
{
"id": 1,
"jsonrpc": "2.0",
"error": {
"code": -32000,
"message": "internal service error",
}
}
return rings node basic information.
POST http://127.0.0.1:50000
Content-Type: application/json
curl -X POST \
-H "Content-Type: application/json" \
--data '{"jsonrpc": "2.0", "id": 1, "method": "nodeInfo", "params": []}' \
"http://127.0.0.1:50000"
version
- current running node versionjson
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"version": "0.0.1"
}
}
Connect a peer with peer's jsonrpc endpoint
POST http://127.0.0.1:50000
Content-Type: application/json
```
curl -X POST \ -H "Content-Type: application/json" \ --data '{"jsonrpc": "2.0", "id": 1, "method": "connectPeerViaHttp", "params": ["REMOTE-JSONRPC-ENDPOINT"]}' \ "http://127.0.0.1:50000" ```
transport_did
- the id of transportjson
{
"jsonrpc": "2.0",
"id": 1,
"result": [
"abcd-1234"
]
}
Connect a peer with peer's did
POST http://127.0.0.1:50000
Content-Type: application/json
X-SIGNATURE: YOUR-SIGNATURE
```
curl -X POST \ -H "Content-Type: application/json" \ -H "X-SIGNATURE: YOUR-SIGNATURE" \ --data '{"jsonrpc": "2.0", "id": 1, "method": "connectPeerWithDid", "params": ["REMOTE-PEER-DID"]}' \ "http://127.0.0.1:50000" ```
json
{
"jsonrpc": "2.0",
"id": 1,
"result": null
}
Connect a peer with peer's seed
POST http://127.0.0.1:50000
Content-Type: application/json
X-SIGNATURE: YOUR-SIGNATURE
```
curl -X POST \ -H "Content-Type: application/json" \ -H "X-SIGNATURE: YOUR-SIGNATURE" \ --data '{"jsonrpc": "2.0", "id": 1, "method": "connectPeerWithSeed", "params": ["REMOTE-PEER-SEED"]}' \ "http://127.0.0.1:50000" ```
json
{
"jsonrpc": "2.0",
"id": 1,
"result": null
}
Create an offer for connection
POST http://127.0.0.1:50000
Content-Type: application/json
X-SIGNATURE: YOUR-SIGNATURE
```
curl -X POST \ -H "Content-Type: application/json" \ -H "X-SIGNATURE: YOUR-SIGNATURE" \ --data '{"jsonrpc": "2.0", "id": 1, "method": "createOffer", "params": []}' \ "http://127.0.0.1:50000" ```
transport_id
: id of the transportice
: ice messagejson
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"transport_id": "1234",
"ice": "abcd1234",
}
}
Answer an offer for connection
POST http://127.0.0.1:50000
Content-Type: application/json
X-SIGNATURE: YOUR-SIGNATURE
```
curl -X POST \ -H "Content-Type: application/json" \ -H "X-SIGNATURE: YOUR-SIGNATURE" \ --data '{"jsonrpc": "2.0", "id": 1, "method": "createOffer", "params": ["REMOTE-PEER-SEED"]}' \ "http://127.0.0.1:50000" ```
transport_id
: id of the transportice
: ice messagejson
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"transport_id": "1234",
"ice": "abcd1234",
}
}
List all node connected peers
POST http://127.0.0.1:50000
Content-Type: application/json
X-SIGNATURE: YOUR-SIGNATURE
```
curl -X POST \ -H "Content-Type: application/json" \ -H "X-SIGNATURE: YOUR-SIGNATURE" \ --data '{"jsonrpc": "2.0", "id": 1, "method": "listPeers", "params": []}' \ "http://127.0.0.1:50000" ```
peers
- list of connected peers
transport_id
- id of the transportdid
- did of remote peerstate
- transport statejson
{
"jsonrpc": "2.0",
"id": 1,
"result": [
{
"did": "abcd1234"
"transport_id": "1234",
"state": "connected",
}
]
}
Close a connected connection with the did of peer
POST http://127.0.0.1:50000
Content-Type: application/json
X-SIGNATURE: YOUR-SIGNATURE
```
curl -X POST \ -H "Content-Type: application/json" \ -H "X-SIGNATURE: YOUR-SIGNATURE" \ --data '{"jsonrpc": "2.0", "id": 1, "method": "closeConnection", "params": ["REMOTE-PEER-DID"]}' \ "http://127.0.0.1:50000" ```
json
{
"jsonrpc": "2.0",
"id": 1,
"result": {}
}
List all pending connections
POST http://127.0.0.1:50000
Content-Type: application/json
X-SIGNATURE: YOUR-SIGNATURE
```
curl -X POST \ -H "Content-Type: application/json" \ -H "X-SIGNATURE: YOUR-SIGNATURE" \ --data '{"jsonrpc": "2.0", "id": 1, "method": "closeConnection", "params": []}' \ "http://127.0.0.1:50000" ```
transport_infos
- list of all pending transports
transport_id
- id of the transportstate
- state of the transportjson
{
"jsonrpc": "2.0",
"id": 1,
"result": [
{
"transport_id": "abcd1234",
"state": "new"
}
]
}
Close a specific pending transport
POST http://127.0.0.1:50000
Content-Type: application/json
X-SIGNATURE: YOUR-SIGNATURE
```
curl -X POST \ -H "Content-Type: application/json" \ -H "X-SIGNATURE: YOUR-SIGNATURE" \ --data '{"jsonrpc": "2.0", "id": 1, "method": "closePendingTransport", "params": ["TRANSPORT-ID"]}' \ "http://127.0.0.1:50000" ```
json
{
"jsonrpc": "2.0",
"id": 1,
"result": {}
}
Send a http request message to remote peer, the remote peer should provide the service you want to use
POST http://127.0.0.1:50000
Content-Type: application/json
X-SIGNATURE: YOUR-SIGNATURE
```
curl -X POST \ -H "Content-Type: application/json" \ -H "X-SIGNATURE: YOUR-SIGNATURE" \ --data '{"jsonrpc": "2.0", "id": 1, "method": "sendSimpleTextMessage", "params": ["REMOTE-PEER-DID", {HTTP-REQUEST-ARG}]}' \ "http://127.0.0.1:50000" ```
name
- service namemethod
- http methodpath
- resource pathtimeout
- timeout of remote request, optionalheaders
- remote request with headers, optionalbody
- request body what you want to send to remote service, optionaltx_id
- transaction idjson
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"tx_id": "abcd1234"
}
}
Send simple text message to a peer
POST http://127.0.0.1:50000
Content-Type: application/json
X-SIGNATURE: YOUR-SIGNATURE
```
curl -X POST \ -H "Content-Type: application/json" \ -H "X-SIGNATURE: YOUR-SIGNATURE" \ --data '{"jsonrpc": "2.0", "id": 1, "method": "sendSimpleTextMessage", "params": ["REMOTE-PEER-DID", "TEXT"]}' \ "http://127.0.0.1:50000" ```
tx_id
- transaction idjson
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"tx_id": "abcd1234"
}
}
Send custom message to a peer
POST http://127.0.0.1:50000
Content-Type: application/json
X-SIGNATURE: YOUR-SIGNATURE
```
curl -X POST \ -H "Content-Type: application/json" \ -H "X-SIGNATURE: YOUR-SIGNATURE" \ --data '{"jsonrpc": "2.0", "id": 1, "method": "sendCustomMessage", "params": ["REMOTE-PEER-DID", "MESSAGE-TYPE", "DATA"]}' \ "http://127.0.0.1:50000" ```
tx_id
- transaction idjson
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"tx_id": "abcd1234"
}
}
Publish data message to specific topic
POST http://127.0.0.1:50000
Content-Type: application/json
X-SIGNATURE: YOUR-SIGNATURE
```
curl -X POST \ -H "Content-Type: application/json" \ -H "X-SIGNATURE: YOUR-SIGNATURE" \ --data '{"jsonrpc": "2.0", "id": 1, "method": "publishMessageToTOpic", "params": ["TOPIC", "DATA"]}' \ "http://127.0.0.1:50000" ```
json
{
"jsonrpc": "2.0",
"id": 1,
"result": {}
}
Fetch message from specific topic
POST http://127.0.0.1:50000
Content-Type: application/json
X-SIGNATURE: YOUR-SIGNATURE
```
curl -X POST \ -H "Content-Type: application/json" \ -H "X-SIGNATURE: YOUR-SIGNATURE" \ --data '{"jsonrpc": "2.0", "id": 1, "method": "fetchMessageToTopic", "params": ["TOPIC", "INDEX"]}' \ "http://127.0.0.1:50000" ```
json
{
"jsonrpc": "2.0",
"id": 1,
"result": [
"topic_message",
]
}
Register custom service to rings network
POST http://127.0.0.1:50000
Content-Type: application/json
X-SIGNATURE: YOUR-SIGNATURE
```
curl -X POST \ -H "Content-Type: application/json" \ -H "X-SIGNATURE: YOUR-SIGNATURE" \ --data '{"jsonrpc": "2.0", "id": 1, "method": "registerService", "params": ["NAME"]}' \ "http://127.0.0.1:50000" ```
json
{
"jsonrpc": "2.0",
"id": 1,
"result": {}
}
Lookup custom service from rings network, you can find all dids of node which provide service you want.
POST http://127.0.0.1:50000
Content-Type: application/json
X-SIGNATURE: YOUR-SIGNATURE
```
curl -X POST \ -H "Content-Type: application/json" \ -H "X-SIGNATURE: YOUR-SIGNATURE" \ --data '{"jsonrpc": "2.0", "id": 1, "method": "lookupService", "params": ["NAME"]}' \ "http://127.0.0.1:50000" ```
json
{
"jsonrpc": "2.0",
"id": 1,
"result": [
"did1",
"did2",
]
}
Use this method, you can pull messages received by this node, to provide your custom service,
But we suggest use websocket
endpoint realtime get messages.
POST http://127.0.0.1:50000
Content-Type: application/json
X-SIGNATURE: YOUR-SIGNATURE
```
curl -X POST \ -H "Content-Type: application/json" \ -H "X-SIGNATURE: YOUR-SIGNATURE" \ --data '{"jsonrpc": "2.0", "id": 1, "method": "pollMessage", "params": ["WAIT"]}' \ "http://127.0.0.1:50000" ```
json
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"message": {
message_type: 1,
data: "base64 text"
}
}
}