magic.lambda.config - Accessing your server’s configuration from Hyperlambda

This project provides configuration settings slots for Magic. The project provides the following slots, allowing you to retrieve configuration settings from your “appsettings.json” configuration file, in addition to saving and loading your configuration file.

How to use [config.get]

This slot allows you to retrieve configuration settings. To retrieve settings you can supply a “path” such as “foo:bar” to for instance an invocation to [config.get]. This will traverse into your “foo” config setting, find its “bar” key, and return the value of your “bar” key. Below is an example of usage.

config.get:"foo:bar"

Assuming your configuration file looks like the following.

{
   "foo": {
      "bar": 42
   }
}

… afterwards the value of your [config.get] node will be the following.

config.get:42

Notice - Due to implementation details of .Net and its IConfiguration specifically, values returned will always be strings, and you’ll have to manually convert these to other types, using for instance the [convert] slot from magic.lambda. This might change in a future release though. You can also provide a default value that will be returned if no configuration value is found, such as the following illustrates.

.foo:foo
config.get:"magic:foo:non-existing-key"
   get-value:x:@.foo

Since the above “non-existing-key” doesn’t exist in your configuration file, the above Hyperlambda will return the value “foo” being the result of the invocation to the [get-value] slot. This allows you to create default values your code resorts to if the specified configuration setting doesn’t exist.

Project website for magic.lambda.config

The source code for this repository can be found at github.com/polterguy/magic.lambda.config, and you can provide feedback, provide bug reports, etc at the same place.

The projects is copyright of Aista, Ltd 2021 - 2023