From c1342bdac6d7c2f603bb69f1c9012833e88e32d6 Mon Sep 17 00:00:00 2001 From: ivaosthu Date: Wed, 11 Jan 2017 15:51:24 +0100 Subject: [PATCH] WIP client specification #201 --- docs/client-spec.md | 11 ---- docs/client-specification.md | 106 +++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 11 deletions(-) delete mode 100644 docs/client-spec.md create mode 100644 docs/client-specification.md diff --git a/docs/client-spec.md b/docs/client-spec.md deleted file mode 100644 index 87f8585aa0..0000000000 --- a/docs/client-spec.md +++ /dev/null @@ -1,11 +0,0 @@ -# Client Specification 1.0 - -This document describes the client contract. - -**TODO:** -- fetch and cache toggles (etag headers etc) -- provide strategies implementations -- evaluate if a feature toggle is enabled or not with the given activation strategies and configurations. -- backup features -- registration -- send metrics \ No newline at end of file diff --git a/docs/client-specification.md b/docs/client-specification.md new file mode 100644 index 0000000000..2ca9055936 --- /dev/null +++ b/docs/client-specification.md @@ -0,0 +1,106 @@ +# Client Specification 1.0 + +This document describes the client contract. + +## The basics +All client implementations should strive to have a simple and consistent user API. +It should be a simple method, called isEnabled, to check if a feature toggle is enabled +or not. The method should return a `boolean` value, true or false. + +``` +unleash.isEnabled("myAwesomeToggle") +``` + +The basic `isEnabled` method should also accept a default value. This should be used if +the client does not know anything about that that toggle name. If the user does not specify +a default value, false should be returned for unknown feature toggles. + +Example: + +``` +boolean value = unleash.isEnabled("unknownFeatureToggle", false); +//value==false because default value was used. +``` + +### Implementation of isEnabled +A feature toggle is defined as: + +```json +{ + "name": "Feature.B", + "description": "lorem ipsum", + "enabled": true, + "strategies": [ + { + "name": "ActiveForUserWithId", + "parameters": { + "userIdList": "123,221,998" + } + }, + { + "name": "GradualRolloutRandom", + "parameters": { + "percentage": "10" + } + } + ], + "strategy": "ActiveForUserWithId", + "parameters": { + "userIdList": "123,221,998" + } + } +``` + +A simple demo of the isEnable function in JavaScript-style (most implementation will probalby be more functional): + +```javascript +function isEnabled(name, defaultValue) { + const toggle = toggleRepository.get(name); + let enabled = false; + + if ( !toggle ) { + return defaultValue; + } else if ( ! toggle.isEnabled) { + return false; + } else { + for(let i=0;i