Skip to content

Latest commit

 

History

History

json-url-stdout

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Json url based Sequence with jsonUrl, interval and jsonPath arguments

This is a Sequence similar to json-url-output. It also pulls the data from JSON url every x seconds and writes it to Instance stdout endpoint, but in this example one more argument is added → jsonPath. The file structure has also changed, the utils.js file has been added, to which the functions responsible for downloading json from the API, the json pull interval and the third function were the jsonPath given in string is converted into a path indicating a specific element nested in the json body.

The Sequence takes three arguments:

Start STH

Use command:

sth or scramjet-transform-hub

Make sure your config is set to local STH: si config reset all

Sequence deployment

Sequence is ready to use, id doesn't use any external modules so no dependencies need to be installed.

Deploy

SI command to deploy the Sequence: si seq deploy <path-to-sequence> --args [<jsonUrl>,<interval>,<jsonPath>], for example:

si seq deploy javascript/json-url-apps/json-seq-2 --args [\"https://www.thecocktaildb.com/api/json/v1/1/search.php?s=margarita\",10000,\"drinks[0].strDrink\"]

Make sure there are no white spaces between the arguments in the args array.

The result of calling this command should be the info printed in the console similar to this one:

$ si seq deploy javascript/json-url-apps/json-seq-2 --args [\"https://www.thecocktaildb.com/api/json/v1/1/search.php?s=margarita\",10000,\"drinks[0].strDrink\"]
InstanceClient {
  host: HostClient {
    apiBase: 'http://127.0.0.1:8000/api/v1',
    client: ClientUtils {
      apiBase: 'http://127.0.0.1:8000/api/v1',
      fetch: [Function (anonymous)],
      normalizeUrlFn: [Function: normalizeUrl]
    }
  },
  _id: '286e1473-dff9-4543-b98b-56285b3953f1',
  instanceURL: 'instance/286e1473-dff9-4543-b98b-56285b3953f1'
}

Read Instance stdout

The result of called sequence's function is a value of key "strDrink" (in this case thi value is "Margarita"). It is printed out in the console using console.log(), it means that the Sequence writes it to stdout instance endpoint. To read this endpoint stream please use the command:

si inst stdout -

Result:

$ si inst stdout -
Margarita
Margarita

The request is sent to API every 10 seconds, so the result will be printed out after every request until the Instance is stopped.