underflag-http
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

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

License

MIT

Package Sidebar

Install

npm i underflag-http

Weekly Downloads

12

Version

1.1.0

License

MIT

Unpacked Size

10.7 kB

Total Files

12

Last publish

Collaborators

  • diego.souza