Skip to main content

Configs

Configs are simple JSON objects which you might need besides entities.

There are two differences between entities and configs:

  1. When you store a config you send an object, while when you store entities you always send them as array, even if you want to store one entity
  2. Configs don't have id propery - they are plain JSON objects.

Think of translations for a website or a light/dark themes for an app for example. When you only want to store plain JSON objects without being restful (having '/model/:id' paths).

How urls are formed?

Once you store a JSON object to nodb, you will have HTTP paths to discover nested JSON properties.

Let's take a frontend app as an example: you're making a React app and you want to store app's theme somewhere on the Internet, instead of storing it locally.

A theme might look like this:

{
"themes": {
"light": {
"color": "#A1A1A1",
"links": {
"normal": "green",
"hover": "lawngreen"
}
},
"dark": {
"color": "#585858",
"links": {
"normal": "darkseagreen",
"hover": "darkgreen"
}
}
}
}

To access properties you only make a GET request to any of them.

# Get all configs
curl https://api.nodb.sh/my-app/dev/configs?token={token}

# Get hover color of light theme
curl https://api.nodb.sh/my-app/dev/configs/themes/light/links/hover?token={token}

How to store configs?

Configs are stored by making a POST request with the JSON payload to the /configs reserved path:

curl -X POST https://api.nodb.sh/my-app/dev/configs?token={token} \
-d '{ "tr": { "en": "Good morning" } }'

Next, you'll access 'tr' config by making a GET request to it:

curl https://api.nodb.sh/my-app/dev/configs/tr?token={token}

Supported methods

  1. GET: fetch all configs or target a specific config's property
  2. POST: create or replace a config
  3. PUT: replace a config's property
  4. PATCH: update a config's property
  5. DELETE: delete all configs, a single config or a config's property.

Learn the details of configs API at API Reference.