Using REST
Users can interact with the nodes in the network using REST.
Using REST, users can execute EdgeLake commands over HTTP on any node in the network that is configured to satisfy REST requests.
Prerequisites
- A REST client software like cUrL or Postman
- An EdgeLake Node that provides a REST connection. To configure an EdgeLake Node to satisfy REST calls, issue the following command on the EdgeLake command line:
<run rest server where
external_ip = [external_ip ip] and
external_port = [external port] and
internal_ip = [internal ip] and
internal_port = [internal port] and
timeout = [timeout] and
ssl = [true/false] and
bind = [true/false]
>
HTTP methods supported
EdgeLake commands are supported using the HTTP methods GET
, PUT
and POST
.
GET
is used to retrieve information.PUT
is used to add data to nodes in the network.POST
is used as a default method to execute all other EdgeLake commands.
HTTP Method | EdgeLake commands | Comments |
---|---|---|
GET | sql | Issue queries to data hosted by nodes of the network |
get | Retrieve information from nodes members of the network | |
blockchain get | Query the metadata | |
help | Help on the ANyLog commands | |
POST | set | Set values or change status |
reset | Reset values or status | |
blockchain | Manage metadata commands (note the `blockchain get` is supported using GET) | |
PUT | command | publish time-series data to node |
Sample cURL Requests
GET
requests
get status
- check whether a node is active or not
curl --location --request GET '10.0.0.78:7849' \
--header 'command: get status' \
--header 'User-Agent: AnyLog/1.23'
blockchain get operator where company='New Company'
- get list of all operators owned by New Company
curl --location --request GET '10.0.0.78:7849' \
--header 'command: blockchain get operator where company="New Company" \
--header 'User-Agent: AnyLog/1.23'
sql new_company format=table "select * from rand_data where timestamp >= NOW() - 1 minute limit 5;"
- SampleSELECT
request
curl --location --request GET '10.0.0.78:7849' \
--header 'command:sql new_company format=table "select * from rand_data where timestamp >= NOW() - 1 minute limit 5;"' \
--header 'User-Agent: AnyLog/1.23' \
--header 'destination: network'
POST
request
The POST
command provides support for both publishing data and all other, non-GET
commands.
When sending data via POST
, there’s a need for mapping between the data comming and organazing it; similar to MQTT. Farther details regardin run msg client
can be found in subscribing to rest calls in AnyLog documentation.
<run msg client where broker=rest and port=!anylo_rest_port and user-agennt=anylog/1.23 and log=false and topic=(
name=new_data and
dbms=bring [dbms] and
table=bring [table] and
column.timestam.timestamp=bring [timestamp] and
column.value=(type=int and value=bring [value])
)>
Sample Calls:
- Adding Data
curl --location --request POST '10.0.0.226:32149' \
--header 'command: data' \
--header 'topic: new_data' \
--header 'User-Agent: AnyLog/1.23' \
--header 'Content-Type: text/plain' \
--data-raw ' [{"dbms" : "aiops", "table" : "fic11", "value": 50, "timestamp": "2019-10-14T17:22:13.051101Z"},
{"dbms" : "aiops", "table" : "fic16", "value": 501, "timestamp": "2019-10-14T17:22:13.050101Z"},
{"dbms" : "aiops", "table" : "ai_mv", "value": 501, "timestamp": "2019-10-14T17:22:13.050101Z"}]'
- Reset (error) log
curl --location --request POST '10.0.0.78:7849' \
--header 'User-Agent: AnyLog/1.23' \
--header 'command: reset error log'
- Set value
curl --location --request POST '10.0.0.78:7849' \
--header 'User-Agent: AnyLog/1.23' \
--header 'command: set company_name=AnyLog'
- Publish Blockchain Policy
curl -X POST \
http://172.18.12.129:2149 \
-H 'command: blockchain push !new_policy' \
-H 'User-Agent: AnyLog/1.23' \
-H 'Content-Type: application/json' \
-d '<new_policy={"panel": {"name": "panel 1", "city": "Los Angeles, CA", "loc": "33.8121, -117.91899", "owner": "AFG"}}>'
PUT
request
Use a REST client software (such as cURL or Postman) and issue a PUT
command to send the data with the following keys and values in the header
Key | Value |
---|---|
User-Agent | AnyLog/1.23 |
type | The type of data transferred. The default value is JSON. |
dbms | The logical database to contain the data. |
table | The logical table to contain the data. |
source | A unique ID to identify the data source (i.e. an ID of a sensor). |
mode | File or Streaming (see details below). The default value is 'file'. |
instructions | An ID of a policy that determines the mapping of the file data to the table's structure. |
curl --location --request PUT '10.0.0.226:32149' \
--header 'type: json' \
--header 'dbms: test' \
--header 'table: table1' \
--header 'Content-Type: text/plain' \
--header 'User-Agent: AnyLog/1.23' \
-w "\n" \
--data-raw '[{"parentelement": "62e71893-92e0-11e9-b465", "webid": "F1AbEfLbwwL8F6EiS", "device_name": "ADVA FSP3000R7", "value": 0, "timestamp": "2019-10-11T17:05:08.0400085Z"},
{"parentelement": "68ae8bef-92e1-11e9-b465", "webid": "F1AbEfLbwwL8F6EiS", "device_name": "Catalyst 3500XL", "value": 50, "timestamp": "2019-10-14T17:22:13.0510101Z"},
{"parentelement": "68ae8bef-92e1-11e9-b465", "webid": "F1AbEfLbwwL8F6EiS", "device_name": "Catalyst 3500XL", "value": 50, "timestamp": "2019-10-14T17:22:18.0360107Z"}]'
Expected Output: {"AnyLog.status":"Success", "AnyLog.hash": "0dd6b959e48c64818bf4748e4ae0c8cb" }