Custom Adapters
Integrate any feature flag provider with the Flags SDK using a custom adapter.
Integrate any feature flag provider with the Flags SDK using an adapter. We publish adapters for the most common providers, but it is also possible to write a custom adapter in case we don't list your provider or in case you have an in-house solution for feature flags.
Adapters conceptually replace the decide
and origin
parts of a flag declaration.
How to write a custom adapter
Creating custom adapters is possible by creating an adapter factory:
This allows passing the provider in the flag declaration.
Example
Below is an example of an Flags SDK adapter reading Edge Config.
Exposing default adapters
In the example above, as a user of the adapter, we first needed to create an instance of the adapter. It is possible to simplify usage further by exposing a default adapter.
Usage with a default adapter, where we can import a fully configured
exampleAdapter
.
Many @flags-sdk/*
adapters will implement this pattern. The
default adapter will get created lazily on first usage, and can
initialize itself based on known environment variables.