App

Obniz.App is a utility class with useful features in app.

When you create a browser app in obniz cloud and run it in the browser or cloud, some global variables are inserted into the HTML. This class provides a way to handle them conveniently.

Obniz.App.configs()

You can read the settings you made during the installation of the app. It can be used in both the app's browser and cloud execution.

// JavaScript Example
const userconfig = Obniz.App.configs();
console.log(userconfig.watering_interval); // User configured value

Obniz.App.isCloudRunning()

Differentiate whether the app is running in the obniz cloud or in the user's browser.

// JavaScript Example
if (Obniz.App.isCloudRunning()) {
  const req = Obniz.App.req();
  console.log(req.query);
  console.log(req.body);
}

Obniz.App.req()

Contains a request object when executed in the cloud in the wake of a webhook.

// JavaScript Example
if (Obniz.App.isCloudRunning()) {
  const req = Obniz.App.req();
  console.log(req.query);
  console.log(req.body);
}

Obniz.App.done()

Terminate the cloud execution and record the results.

You can choose from the following two types of status

  • 'success'.
  • 'error'

The text can be any string

// JavaScript Example
if (Obniz.App.isCloudRunning()) {
  var temp = '27'
  Obniz.App.done({
    status: 'success',
    text: `${tmp} degree`
  })
}