1.1.0 • Published 2 years ago
underflag-http v1.1.0
HTTP Provider
This is a HTTP provider for underflag (feature flag/feature toggle) than help your app to load the features from a json object or an array of json object from web. You can get easly from the Github json file, AWS S3 or a Rest API with custom token too.
Install
Using npm:
npm install underflag underflag-http
Using yarn:
yarn add underflag underflag-http
How to use
Import the underflag and prepare to load data provider
import { Underflag } from "underflag";
import { HttpDataProvider } from "underflag-http";
const dataProvider = new HttpDataProvider({
url: 'http://localhost:3000/features'
});
const underflag = new Underflag({ dataProvider });
if (await underflag.isOn("feature")) {
// ...
}
Important: The url need return a json object or an array of json object
Eg. json object:
{
"feature": true
}
Eg. array of json object:
[
{
"key": "feature",
"value": true
}
]
If you need getting data from nested field like:
{
"data": [
{
"key": "feature",
"value": true
}
]
}
You can setting the path of the field:
const dataProvider = new HttpDataProvider({
url: 'http://localhost:3000/features',
nestedField: 'data'
});
The nestedField option use lodash.get, know more about lodash.get on https://lodash.com/docs#get
Know more on underflag npm page