NestJS
Installation
Add the OpenFeature SDK and the Tggl Provider to your project:
Quick start
Configure the OpenFeatureModule
with the TgglServerProvider
in your application module:
You can now inject flag evaluation details into route handlers like so:
You can also inject the client to evaluate flags in your services:
Getting a flag's value
There are four methods to get a flag's value: getBooleanValue
, getNumberValue
, getStringValue
, and getObjectValue
. Those four methods return a Promise, but evaluation is done locally and no API call is performed.
Each method takes the flag's key as the first argument, a default value as the second argument, and an optional context object as the third argument.
The default value must be specified and will be returned if the flag is not found or if an error occurs.
When calling either getBooleanValue
, getNumberValue
, or getStringValue
, the value will be cast to the appropriate type. If you are unsure of the type of the flag, use getObjectValue
to get the raw value which may be of any valid JSON value, including boolean, string, and number.
Polling for "live" updates
If you need your client to be up-to-date with the latest flag configuration, you can enable polling:
Here, the provider will poll the Tggl API every 5 seconds for updates. You can be notified when the configuration changes by listening to the ConfigurationChanged
event:
This is a good time to recompute flags where you need a "live" value.
Using the Proxy
By default, the Provider talks directly to the Tggl API. If you are using the Tggl Proxy, you can specify the proxy URL when instantiating the provider:
The /config
and /report
path will be appended to the baseUrl
and both flags evaluation and reporting will go through the proxy. If your proxy is configured with custom paths, you can specify them:
Going further
Read the official OpenFeature SDK documentation for more information on how to use the SDK.
You can also have a look at Tggl's Node.js SDK documentation that is used under the hood by the TgglServerProvider
.