Feature Flags

How do I implement Tenit Feature Flags into my code?

Want the TL;DR or just to see the code? Check out the source code used in this video on Github here: Github Examples

 

Here's a demo video walking through a full end to end example of code, the requests, updating the feature flags, and how it shows up to end users:

 

 

 

Tenit Features can be checked using an HTTP request to the API

GET https://features.tenitx.com/${feature}/enabled?user=${userId}

Make sure to include the required x-tenit-api-token header with the request, and the value of that header should be an API token for your account with permission to read features. Find or create an API token for your account here

The response from this request will be a json object with a single field of "enabled", like this:

{
"enabled": true
}

 

Once we've captured the response of the request into a variable, let's call it "isEnabled", we can conditionally run different logic depending on if the feature is enabled or not.

 

Backend Style Example:

Let's say we want to implement a new data fetching pattern for how we get data from our database, and we want to put a cache in front of the database request. We feel pretty confident about our plan, but this runs in a critical code path and we're not sure if we've nailed the cache eviction strategy just yet.

We could implement the below code using the response from the above feature flag request to slowly and confidently move traffic over to our new caching strategy.

// isEnabled -- Represents the feature flag response

if (isEnabled) {
  fetchDataFromCacheWithDbFallback(); 
} else {
  fetchDataFromDb();
}

 

Frontend Style Example (React style):

(This example is similar to what was shown in the walkthrough video)

Let's say we have an existing form today that allow customers to submit support requests, but now we want to add some new fields to it and add some nice quality of life upgrades to the form like pre-filling the user's email since we already have that since their logged into our app.

We could implement the below code using the response from the above feature flag request to slowly and confidently start showing the new form to users.

// isEnabled -- Represents the feature flag response

if (isEnabled) {
return (<UpgradedForm />);
}

return (<ExistingForm />);