Code Monkey home page Code Monkey logo

package-json-config's Introduction

Example on how to use JSON config values

Import this package into your info-beamer account.

Import

This package shows how you might build a package that contains both user controlled values as well as an automatically updated part that is updated only using the API.

The top-level node.json file specifies a playlist as an example of a user configurable option.

Inside the automated directory there's another node.json file. It shows two fields of type json that can be changed only using the API.

Updating is easy:

curl -u:$API_KEY https://info-beamer.com/api/v1/setup/$SETUP_ID -d 'config={"automated":{"config_value1":{"foo":"bar"}}}&mode=update'

(Note: You shouldn't use raw curl for the API as the arguments to config should be urlencoded. Use a propery HTTP request library in your language of choice to do this correctly.)

By specifying the mode=update parameter, the above call only changes the config_value1 value in the automated subdirectory. The user made settings in the top-level node remain unchanged. If you have multiple json types in your node.json, like in this example, you can of course also modify them all at once with a single HTTP call:

curl ... 'config={"automated":{"config_value1":{"foo":"bar"},"config_value2": 1234}}&mode=update'

Inside your node.lua code you can easily watch both the top-level config.json as well as the automated/config.json file using the util.json_watch helper function. See the node.lua code in the package for details.

Using the json data type for all configuration options allows you to place arbitrary values in the configuration itself and inside Lua you can directly access them in the util.json_watch callback. No extra parsing is required.

package-json-config's People

Contributors

dividuum avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.