-
Notifications
You must be signed in to change notification settings - Fork 3
/
client-specification.html
34 lines (24 loc) · 44.9 KB
/
client-specification.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<!doctype html>
<html lang="en" dir="ltr" class="docs-wrapper docs-doc-page docs-version-current plugin-docs plugin-id-default docs-doc-id-client-specification">
<head>
<meta charset="UTF-8">
<meta name="generator" content="Docusaurus v2.3.1">
<title data-rh="true">Client Specification | Unleash</title><meta data-rh="true" name="viewport" content="width=device-width,initial-scale=1"><meta data-rh="true" name="twitter:card" content="summary_large_image"><meta data-rh="true" property="og:image" content="https://docs.getunleash.io/img/logo.png"><meta data-rh="true" name="twitter:image" content="https://docs.getunleash.io/img/logo.png"><meta data-rh="true" property="og:url" content="https://docs.getunleash.io/client-specification"><meta data-rh="true" name="docusaurus_locale" content="en"><meta data-rh="true" name="docsearch:language" content="en"><meta data-rh="true" name="docusaurus_version" content="current"><meta data-rh="true" name="docusaurus_tag" content="docs-default-current"><meta data-rh="true" name="docsearch:version" content="current"><meta data-rh="true" name="docsearch:docusaurus_tag" content="docs-default-current"><meta data-rh="true" property="og:title" content="Client Specification | Unleash"><meta data-rh="true" name="description" content="This document attempts to guide developers in implementing an Unleash Client SDK."><meta data-rh="true" property="og:description" content="This document attempts to guide developers in implementing an Unleash Client SDK."><link data-rh="true" rel="icon" href="/img/favicon.ico"><link data-rh="true" rel="canonical" href="https://docs.getunleash.io/client-specification"><link data-rh="true" rel="alternate" href="https://docs.getunleash.io/client-specification" hreflang="en"><link data-rh="true" rel="alternate" href="https://docs.getunleash.io/client-specification" hreflang="x-default"><link data-rh="true" rel="preconnect" href="https://5U05JI5NE1-dsn.algolia.net" crossorigin="anonymous"><link rel="preconnect" href="https://www.google-analytics.com">
<script>window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)},ga.l=+new Date,ga("create","UA-134882379-1","auto"),ga("send","pageview")</script>
<script async src="https://www.google-analytics.com/analytics.js"></script>
<link rel="preconnect" href="https://www.googletagmanager.com">
<script>window.dataLayer=window.dataLayer||[]</script>
<script>!function(e,t,a,n,g){e[n]=e[n]||[],e[n].push({"gtm.start":(new Date).getTime(),event:"gtm.js"});var m=t.getElementsByTagName(a)[0],r=t.createElement(a);r.async=!0,r.src="https://www.googletagmanager.com/gtm.js?id=GTM-KV5PRR2",m.parentNode.insertBefore(r,m)}(window,document,"script","dataLayer")</script>
<link rel="search" type="application/opensearchdescription+xml" title="Unleash" href="/opensearch.xml">
<script src="https://widget.kapa.ai/kapa-widget.bundle.js" data-website-id="1d187510-1726-4011-b0f7-62742ae064ee" data-project-name="Unleash" data-project-color="#1A4049" data-project-logo="https://cdn.getunleash.io/uploads/2022/05/logo.png" async></script><link rel="stylesheet" href="/assets/css/styles.68ed099b.css">
<link rel="preload" href="/assets/js/runtime~main.60bdb37d.js" as="script">
<link rel="preload" href="/assets/js/main.3c1b2d68.js" as="script">
</head>
<body class="navigation-with-keyboard">
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-KV5PRR2" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<script>!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){var t=null;try{t=localStorage.getItem("theme")}catch(t){}return t}();t(null!==e?e:"light")}()</script><div id="__docusaurus">
<div role="region" aria-label="Skip to main content"><a class="skipToContent_fXgn" href="#docusaurus_skipToContent_fallback">Skip to main content</a></div><nav aria-label="Main" class="navbar navbar--fixed-top"><div class="navbar__inner"><div class="navbar__items"><button aria-label="Toggle navigation bar" aria-expanded="false" class="navbar__toggle clean-btn" type="button"><svg width="30" height="30" viewBox="0 0 30 30" aria-hidden="true"><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></button><a class="navbar__brand" href="/"><div class="navbar__logo"><img src="/img/unleash_logo_white.svg" alt="Unleash logo" class="themedImage_ToTc themedImage--light_HNdA"><img src="/img/unleash_logo_white.svg" alt="Unleash logo" class="themedImage_ToTc themedImage--dark_i4oU"></div></a></div><div class="navbar__items navbar__items--right"><a class="navbar__item navbar__link" href="/quickstart">Quickstart</a><a class="navbar__item navbar__link" href="/">Docs</a><div class="navbar__item dropdown dropdown--hoverable dropdown--right"><a class="navbar__link" aria-haspopup="true" aria-expanded="false" role="button" href="/unleash-academy/introduction"><span class="hide-at-small-sizes">Unleash </span>Academy</a><ul class="dropdown__menu"><li><a class="dropdown__link" href="/unleash-academy/foundational">Foundational</a></li><li><a class="dropdown__link" href="/unleash-academy/advanced-for-devs">Advanced for Developers</a></li><li><a class="dropdown__link" href="/unleash-academy/managing-unleash-for-devops">Managing Unleash for DevOps/Admins</a></li></ul></div><div class="navbar__item dropdown dropdown--hoverable dropdown--right"><a href="#" aria-haspopup="true" aria-expanded="false" role="button" class="navbar__link"><span class="hide-at-small-sizes">Unleash </span>Certification</a><ul class="dropdown__menu"><li><a href="https://docs.google.com/forms/d/1iPUk2I0k5xMzicn9aLMcPF3b9ub3ZwdVjRxCxWxV7js/viewform" target="_blank" rel="noopener noreferrer" class="dropdown__link">Foundational Unleash<svg width="12" height="12" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li><li><a href="https://docs.google.com/forms/d/1NUL9hyO8Ys916TB6fPV3-jkvD97OmPXZ8_TO84Wjqgc/viewform" target="_blank" rel="noopener noreferrer" class="dropdown__link">Advanced Unleash for Developers<svg width="12" height="12" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li><li><a href="https://docs.google.com/forms/d/1JlIqmXI3P7dj0n-OiUs2IYsYXgmqw23BChaemlSgHJA/viewform" target="_blank" rel="noopener noreferrer" class="dropdown__link">Managing Unleash for DevOps/Admins<svg width="12" height="12" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li></ul></div><div class="navbar__item"><span class="navbar-separator"></span></div><a href="https://www.getunleash.io/plans" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">Plans<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a><a href="https://app.unleash-hosted.com/sign-in" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">Sign in<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a><div class="navbar__item"><span class="navbar-separator"></span></div><a href="https://github.com/Unleash/unleash" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link header-github-link" aria-label="Unleash GitHub repository"></a><div class="toggle_vylO colorModeToggle_DEke"><button class="clean-btn toggleButton_gllP toggleButtonDisabled_aARS" type="button" disabled="" title="Switch between dark and light mode (currently light mode)" aria-label="Switch between dark and light mode (currently light mode)" aria-live="polite"><svg viewBox="0 0 24 24" width="24" height="24" class="lightToggleIcon_pyhR"><path fill="currentColor" d="M12,9c1.65,0,3,1.35,3,3s-1.35,3-3,3s-3-1.35-3-3S10.35,9,12,9 M12,7c-2.76,0-5,2.24-5,5s2.24,5,5,5s5-2.24,5-5 S14.76,7,12,7L12,7z M2,13l2,0c0.55,0,1-0.45,1-1s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S1.45,13,2,13z M20,13l2,0c0.55,0,1-0.45,1-1 s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S19.45,13,20,13z M11,2v2c0,0.55,0.45,1,1,1s1-0.45,1-1V2c0-0.55-0.45-1-1-1S11,1.45,11,2z M11,20v2c0,0.55,0.45,1,1,1s1-0.45,1-1v-2c0-0.55-0.45-1-1-1C11.45,19,11,19.45,11,20z M5.99,4.58c-0.39-0.39-1.03-0.39-1.41,0 c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0s0.39-1.03,0-1.41L5.99,4.58z M18.36,16.95 c-0.39-0.39-1.03-0.39-1.41,0c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0c0.39-0.39,0.39-1.03,0-1.41 L18.36,16.95z M19.42,5.99c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06c-0.39,0.39-0.39,1.03,0,1.41 s1.03,0.39,1.41,0L19.42,5.99z M7.05,18.36c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06 c-0.39,0.39-0.39,1.03,0,1.41s1.03,0.39,1.41,0L7.05,18.36z"></path></svg><svg viewBox="0 0 24 24" width="24" height="24" class="darkToggleIcon_wfgR"><path fill="currentColor" d="M9.37,5.51C9.19,6.15,9.1,6.82,9.1,7.5c0,4.08,3.32,7.4,7.4,7.4c0.68,0,1.35-0.09,1.99-0.27C17.45,17.19,14.93,19,12,19 c-3.86,0-7-3.14-7-7C5,9.07,6.81,6.55,9.37,5.51z M12,3c-4.97,0-9,4.03-9,9s4.03,9,9,9s9-4.03,9-9c0-0.46-0.04-0.92-0.1-1.36 c-0.98,1.37-2.58,2.26-4.4,2.26c-2.98,0-5.4-2.42-5.4-5.4c0-1.81,0.89-3.42,2.26-4.4C12.92,3.04,12.46,3,12,3L12,3z"></path></svg></button></div><div class="searchBox_ZlJk"><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><span class="DocSearch-Button-Container"><svg width="20" height="20" class="DocSearch-Search-Icon" viewBox="0 0 20 20"><path d="M14.386 14.386l4.0877 4.0877-4.0877-4.0877c-2.9418 2.9419-7.7115 2.9419-10.6533 0-2.9419-2.9418-2.9419-7.7115 0-10.6533 2.9418-2.9419 7.7115-2.9419 10.6533 0 2.9419 2.9418 2.9419 7.7115 0 10.6533z" stroke="currentColor" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"></path></svg><span class="DocSearch-Button-Placeholder">Search</span></span><span class="DocSearch-Button-Keys"></span></button></div></div></div><div role="presentation" class="navbar-sidebar__backdrop"></div></nav><div id="docusaurus_skipToContent_fallback" class="main-wrapper mainWrapper_z2l0 docsWrapper_BCFX"><button aria-label="Scroll back to top" class="clean-btn theme-back-to-top-button backToTopButton_sjWU" type="button"></button><div class="docPage__5DB"><main class="docMainContainer_gTbr docMainContainerEnhanced_Uz_u"><div class="container padding-top--md padding-bottom--lg"><div class="row"><div class="col docItemCol_BDYx"><div class="docItemContainer_oq1c"><article><div class="tocCollapsible_ETCw theme-doc-toc-mobile tocMobile_ITEo"><button type="button" class="clean-btn tocCollapsibleButton_TO0P">On this page</button></div><div class="theme-doc-markdown markdown"><div class="row"><div class="col col--12"><h1>Client Specification 1.0</h1><p>This document attempts to guide developers in implementing an Unleash Client SDK.</p><h2 class="anchor anchorWithStickyNavbar_LWe7" id="system-overview">System Overview<a href="#system-overview" class="hash-link" aria-label="Direct link to System Overview" title="Direct link to System Overview"></a></h2><p>Unleash is composed of three parts:</p><ul><li><strong>Unleash API</strong> - The service holding all feature toggles and their configurations. Configurations declare which activation strategies to use and which parameters they should get.</li><li><strong>Unleash UI</strong> - The dashboard used to manage feature toggles, define new strategies, look at metrics, etc.</li><li><strong>Unleash SDK</strong> - Used by clients to check if a feature is enabled or disabled. The SDK also collects metrics and sends them to the Unleash API. Activation Strategies are also implemented in the SDK. Unleash currently provides official SDKs for Java and Node.js</li></ul><p><img loading="lazy" alt="system_overview" src="/assets/images/unleash-diagram-f346275dba31971141f2ab15f8a5a7b5.png" title="System Overview" width="508" height="324" class="img_ev3q"></p><p>To be super fast, the client SDK caches all feature toggles and their current configuration in memory. The activation strategies are also implemented in the SDK. This makes it really fast to check if a toggle is on or off because it is just a simple function operating on local state, without the need to poll data from the database.</p><h2 class="anchor anchorWithStickyNavbar_LWe7" id="the-basics">The Basics<a href="#the-basics" class="hash-link" aria-label="Direct link to The Basics" title="Direct link to The Basics"></a></h2><p>All client implementations should strive to have a consistent and straightforward 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 <code>boolean</code> value, true or false.</p><div class="language-javascript codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:#282c34;--prism-color:#ffffff"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-javascript codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#ffffff"><span class="token plain">unleash</span><span class="token punctuation" style="color:#8dc891">.</span><span class="token method function property-access" style="color:#79b6f2">isEnabled</span><span class="token punctuation" style="color:#8dc891">(</span><span class="token string" style="color:#8dc891">'myAwesomeToggle'</span><span class="token punctuation" style="color:#8dc891">)</span><span class="token punctuation" style="color:#8dc891">;</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><p>The basic <code>isEnabled</code> method should also accept a default value. This should be used if the client does not know anything about a particular toggle. If the user does not specify a default value, false should be returned for unknown feature toggles.</p><p><strong>Calling unleash with default value:</strong></p><div class="language-javascript codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:#282c34;--prism-color:#ffffff"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-javascript codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#ffffff"><span class="token plain">boolean value </span><span class="token operator" style="color:#d7deea">=</span><span class="token plain"> unleash</span><span class="token punctuation" style="color:#8dc891">.</span><span class="token method function property-access" style="color:#79b6f2">isEnabled</span><span class="token punctuation" style="color:#8dc891">(</span><span class="token string" style="color:#8dc891">"unknownFeatureToggle"</span><span class="token punctuation" style="color:#8dc891">,</span><span class="token plain"> </span><span class="token boolean" style="color:#ff8b50">false</span><span class="token punctuation" style="color:#8dc891">)</span><span class="token punctuation" style="color:#8dc891">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"></span><span class="token comment" style="color:#999999">//value==false because default value was used.</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><h3 class="anchor anchorWithStickyNavbar_LWe7" id="implementation-of-isenabled">Implementation of isEnabled<a href="#implementation-of-isenabled" class="hash-link" aria-label="Direct link to Implementation of isEnabled" title="Direct link to Implementation of isEnabled"></a></h3><p>A feature toggle is defined as:</p><div class="language-json codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:#282c34;--prism-color:#ffffff"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-json codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#ffffff"><span class="token punctuation" style="color:#8dc891">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"> </span><span class="token property" style="color:#5a9bcf">"name"</span><span class="token operator" style="color:#d7deea">:</span><span class="token plain"> </span><span class="token string" style="color:#8dc891">"Feature.B"</span><span class="token punctuation" style="color:#8dc891">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"> </span><span class="token property" style="color:#5a9bcf">"description"</span><span class="token operator" style="color:#d7deea">:</span><span class="token plain"> </span><span class="token string" style="color:#8dc891">"lorem ipsum"</span><span class="token punctuation" style="color:#8dc891">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"> </span><span class="token property" style="color:#5a9bcf">"enabled"</span><span class="token operator" style="color:#d7deea">:</span><span class="token plain"> </span><span class="token boolean" style="color:#ff8b50">true</span><span class="token punctuation" style="color:#8dc891">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"> </span><span class="token property" style="color:#5a9bcf">"strategies"</span><span class="token operator" style="color:#d7deea">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#8dc891">[</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"> </span><span class="token punctuation" style="color:#8dc891">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"> </span><span class="token property" style="color:#5a9bcf">"name"</span><span class="token operator" style="color:#d7deea">:</span><span class="token plain"> </span><span class="token string" style="color:#8dc891">"ActiveForUserWithId"</span><span class="token punctuation" style="color:#8dc891">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"> </span><span class="token property" style="color:#5a9bcf">"parameters"</span><span class="token operator" style="color:#d7deea">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#8dc891">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"> </span><span class="token property" style="color:#5a9bcf">"userIdList"</span><span class="token operator" style="color:#d7deea">:</span><span class="token plain"> </span><span class="token string" style="color:#8dc891">"123,221,998"</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"> </span><span class="token punctuation" style="color:#8dc891">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"> </span><span class="token punctuation" style="color:#8dc891">}</span><span class="token punctuation" style="color:#8dc891">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"> </span><span class="token punctuation" style="color:#8dc891">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"> </span><span class="token property" style="color:#5a9bcf">"name"</span><span class="token operator" style="color:#d7deea">:</span><span class="token plain"> </span><span class="token string" style="color:#8dc891">"GradualRolloutRandom"</span><span class="token punctuation" style="color:#8dc891">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"> </span><span class="token property" style="color:#5a9bcf">"parameters"</span><span class="token operator" style="color:#d7deea">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#8dc891">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"> </span><span class="token property" style="color:#5a9bcf">"percentage"</span><span class="token operator" style="color:#d7deea">:</span><span class="token plain"> </span><span class="token string" style="color:#8dc891">"10"</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"> </span><span class="token punctuation" style="color:#8dc891">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"> </span><span class="token punctuation" style="color:#8dc891">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"> </span><span class="token punctuation" style="color:#8dc891">]</span><span class="token punctuation" style="color:#8dc891">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"> </span><span class="token property" style="color:#5a9bcf">"strategy"</span><span class="token operator" style="color:#d7deea">:</span><span class="token plain"> </span><span class="token string" style="color:#8dc891">"ActiveForUserWithId"</span><span class="token punctuation" style="color:#8dc891">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"> </span><span class="token property" style="color:#5a9bcf">"parameters"</span><span class="token operator" style="color:#d7deea">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#8dc891">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"> </span><span class="token property" style="color:#5a9bcf">"userIdList"</span><span class="token operator" style="color:#d7deea">:</span><span class="token plain"> </span><span class="token string" style="color:#8dc891">"123,221,998"</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"> </span><span class="token punctuation" style="color:#8dc891">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"></span><span class="token punctuation" style="color:#8dc891">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><p>A simple demo of the <code>isEnabled</code> function in JavaScript style (most of the implementation will likely be more functional):</p><div class="language-javascript codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:#282c34;--prism-color:#ffffff"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-javascript codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#ffffff"><span class="token keyword" style="color:#c5a5c5">function</span><span class="token plain"> </span><span class="token function" style="color:#79b6f2">isEnabled</span><span class="token punctuation" style="color:#8dc891">(</span><span class="token parameter">name</span><span class="token parameter punctuation" style="color:#8dc891">,</span><span class="token parameter"> unleashContext </span><span class="token parameter operator" style="color:#d7deea">=</span><span class="token parameter"> </span><span class="token parameter punctuation" style="color:#8dc891">{</span><span class="token parameter punctuation" style="color:#8dc891">}</span><span class="token parameter punctuation" style="color:#8dc891">,</span><span class="token parameter"> defaultValue </span><span class="token parameter operator" style="color:#d7deea">=</span><span class="token parameter"> </span><span class="token parameter boolean" style="color:#ff8b50">false</span><span class="token punctuation" style="color:#8dc891">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#8dc891">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"> </span><span class="token keyword" style="color:#c5a5c5">const</span><span class="token plain"> toggle </span><span class="token operator" style="color:#d7deea">=</span><span class="token plain"> toggleRepository</span><span class="token punctuation" style="color:#8dc891">.</span><span class="token method function property-access" style="color:#79b6f2">get</span><span class="token punctuation" style="color:#8dc891">(</span><span class="token plain">name</span><span class="token punctuation" style="color:#8dc891">)</span><span class="token punctuation" style="color:#8dc891">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"> </span><span class="token keyword" style="color:#c5a5c5">let</span><span class="token plain"> enabled </span><span class="token operator" style="color:#d7deea">=</span><span class="token plain"> </span><span class="token boolean" style="color:#ff8b50">false</span><span class="token punctuation" style="color:#8dc891">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"> </span><span class="token keyword control-flow" style="color:#c5a5c5">if</span><span class="token plain"> </span><span class="token punctuation" style="color:#8dc891">(</span><span class="token operator" style="color:#d7deea">!</span><span class="token plain">toggle</span><span class="token punctuation" style="color:#8dc891">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#8dc891">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"> </span><span class="token keyword control-flow" style="color:#c5a5c5">return</span><span class="token plain"> defaultValue</span><span class="token punctuation" style="color:#8dc891">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"> </span><span class="token punctuation" style="color:#8dc891">}</span><span class="token plain"> </span><span class="token keyword control-flow" style="color:#c5a5c5">else</span><span class="token plain"> </span><span class="token keyword control-flow" style="color:#c5a5c5">if</span><span class="token plain"> </span><span class="token punctuation" style="color:#8dc891">(</span><span class="token operator" style="color:#d7deea">!</span><span class="token plain">toggle</span><span class="token punctuation" style="color:#8dc891">.</span><span class="token property-access">isEnabled</span><span class="token punctuation" style="color:#8dc891">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#8dc891">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"> </span><span class="token keyword control-flow" style="color:#c5a5c5">return</span><span class="token plain"> </span><span class="token boolean" style="color:#ff8b50">false</span><span class="token punctuation" style="color:#8dc891">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"> </span><span class="token punctuation" style="color:#8dc891">}</span><span class="token plain"> </span><span class="token keyword control-flow" style="color:#c5a5c5">else</span><span class="token plain"> </span><span class="token punctuation" style="color:#8dc891">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"> </span><span class="token keyword control-flow" style="color:#c5a5c5">for</span><span class="token plain"> </span><span class="token punctuation" style="color:#8dc891">(</span><span class="token keyword" style="color:#c5a5c5">let</span><span class="token plain"> i </span><span class="token operator" style="color:#d7deea">=</span><span class="token plain"> </span><span class="token number" style="color:#5a9bcf">0</span><span class="token punctuation" style="color:#8dc891">;</span><span class="token plain"> i </span><span class="token operator" style="color:#d7deea"><</span><span class="token plain"> toggle</span><span class="token punctuation" style="color:#8dc891">.</span><span class="token property-access">strategies</span><span class="token punctuation" style="color:#8dc891">.</span><span class="token property-access">length</span><span class="token punctuation" style="color:#8dc891">;</span><span class="token plain"> i</span><span class="token operator" style="color:#d7deea">++</span><span class="token punctuation" style="color:#8dc891">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#8dc891">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"> </span><span class="token keyword" style="color:#c5a5c5">let</span><span class="token plain"> strategyDef </span><span class="token operator" style="color:#d7deea">=</span><span class="token plain"> toggle</span><span class="token punctuation" style="color:#8dc891">.</span><span class="token property-access">strategies</span><span class="token punctuation" style="color:#8dc891">[</span><span class="token plain">i</span><span class="token punctuation" style="color:#8dc891">]</span><span class="token punctuation" style="color:#8dc891">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"> </span><span class="token keyword" style="color:#c5a5c5">let</span><span class="token plain"> strategyImpl </span><span class="token operator" style="color:#d7deea">=</span><span class="token plain"> strategyImplRepository</span><span class="token punctuation" style="color:#8dc891">.</span><span class="token method function property-access" style="color:#79b6f2">get</span><span class="token punctuation" style="color:#8dc891">(</span><span class="token plain">strategyDef</span><span class="token punctuation" style="color:#8dc891">.</span><span class="token property-access">name</span><span class="token punctuation" style="color:#8dc891">)</span><span class="token punctuation" style="color:#8dc891">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"> </span><span class="token keyword control-flow" style="color:#c5a5c5">if</span><span class="token plain"> </span><span class="token punctuation" style="color:#8dc891">(</span><span class="token plain">strategyImpl</span><span class="token punctuation" style="color:#8dc891">.</span><span class="token method function property-access" style="color:#79b6f2">isEnabled</span><span class="token punctuation" style="color:#8dc891">(</span><span class="token plain">toggle</span><span class="token punctuation" style="color:#8dc891">.</span><span class="token property-access">parameters</span><span class="token punctuation" style="color:#8dc891">,</span><span class="token plain"> unleashContext</span><span class="token punctuation" style="color:#8dc891">)</span><span class="token punctuation" style="color:#8dc891">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#8dc891">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"> </span><span class="token keyword control-flow" style="color:#c5a5c5">return</span><span class="token plain"> </span><span class="token boolean" style="color:#ff8b50">true</span><span class="token punctuation" style="color:#8dc891">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"> </span><span class="token punctuation" style="color:#8dc891">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"> </span><span class="token punctuation" style="color:#8dc891">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"> </span><span class="token keyword control-flow" style="color:#c5a5c5">return</span><span class="token plain"> </span><span class="token boolean" style="color:#ff8b50">false</span><span class="token punctuation" style="color:#8dc891">;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"> </span><span class="token punctuation" style="color:#8dc891">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#ffffff"><span class="token plain"></span><span class="token punctuation" style="color:#8dc891">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg class="copyButtonIcon_y97N" viewBox="0 0 24 24"><path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg class="copyButtonSuccessIcon_LjdS" viewBox="0 0 24 24"><path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><h2 class="anchor anchorWithStickyNavbar_LWe7" id="activation-strategies">Activation Strategies<a href="#activation-strategies" class="hash-link" aria-label="Direct link to Activation Strategies" title="Direct link to Activation Strategies"></a></h2><p>Activation strategies are defined and configured in the unleash-service. It is up to the client to provide the actual implementation of each activation strategy.</p><p>Unleash also ships with a few built-in strategies, and expects client SDK's to implement these. Read more about these <a href="/reference/activation-strategies">activation strategies</a>. For the built-in strategies to work as expected the client should also allow the user to define an <a href="/reference/unleash-context">unleash-context</a>. The context should be possible to pass in as part of the <code>isEnabled</code> call.</p><h3 class="anchor anchorWithStickyNavbar_LWe7" id="extension-points">Extension points<a href="#extension-points" class="hash-link" aria-label="Direct link to Extension points" title="Direct link to Extension points"></a></h3><p>Client implementation should also provide a defined interface to make it easier for the user to implement their own activation strategies, and register those in the Unleash client.</p><h2 class="anchor anchorWithStickyNavbar_LWe7" id="fetching-feature-toggles-polling">Fetching feature toggles (polling)<a href="#fetching-feature-toggles-polling" class="hash-link" aria-label="Direct link to Fetching feature toggles (polling)" title="Direct link to Fetching feature toggles (polling)"></a></h2><p>The client implementation should fetch toggles in the background as regular polling. In a thread-based environment, such as Java, this needs to be done in a separate thread. The default poll interval should be <strong>15 seconds</strong>, and it should also be configurable.</p><h2 class="anchor anchorWithStickyNavbar_LWe7" id="client-registration">Client registration<a href="#client-registration" class="hash-link" aria-label="Direct link to Client registration" title="Direct link to Client registration"></a></h2><p>On start-up, the clients should register with the Unleash server. The registration request must include the required fields specified in the <a href="/reference/api/legacy/unleash/client/register">API documentation</a>.</p><h2 class="anchor anchorWithStickyNavbar_LWe7" id="metrics">Metrics<a href="#metrics" class="hash-link" aria-label="Direct link to Metrics" title="Direct link to Metrics"></a></h2><p>Clients are expected to send metrics back to Unleash API at regular intervals. The metrics are a list of used toggles and how many times they evaluated to yes or no in at the time of requesting the metrics. Read more about how to send metrics in the <a href="/reference/api/legacy/unleash/client/metrics">Metrics API</a> documentation.</p><h2 class="anchor anchorWithStickyNavbar_LWe7" id="backup-feature-toggles">Backup Feature Toggles<a href="#backup-feature-toggles" class="hash-link" aria-label="Direct link to Backup Feature Toggles" title="Direct link to Backup Feature Toggles"></a></h2><p>The SDK also persists the latest known state to a local file on the instance where the client is running. It will store a local copy every time the client receives changes from the API. Having a local backup of the latest known state minimises the consequences of clients not being able to talk to the Unleash API on startup. This is necessary due to network unreliability.</p></div></div></div><div class="col col--12"><footer class="theme-doc-footer docusaurus-mt-lg"><div class="theme-doc-footer-edit-meta-row row"><div class="col"><a href="https://github.com/Unleash/unleash/edit/main/website/docs/client-specification.md" target="_blank" rel="noreferrer noopener" class="theme-edit-this-page"><svg fill="currentColor" height="20" width="20" viewBox="0 0 40 40" class="iconEdit_Z9Sw" aria-hidden="true"><g><path d="m34.5 11.7l-3 3.1-6.3-6.3 3.1-3q0.5-0.5 1.2-0.5t1.1 0.5l3.9 3.9q0.5 0.4 0.5 1.1t-0.5 1.2z m-29.5 17.1l18.4-18.5 6.3 6.3-18.4 18.4h-6.3v-6.2z"></path></g></svg>Edit this page</a></div><div class="col lastUpdated_vwxv"></div></div></footer></div></article><div class="col col--12"><nav class="pagination-nav docusaurus-mt-lg" aria-label="Docs pages navigation"></nav></div></div></div><div class="col col--3"><div class="tableOfContents_bqdL thin-scrollbar theme-doc-toc-desktop"><ul class="table-of-contents table-of-contents__left-border"><li><a href="#system-overview" class="table-of-contents__link toc-highlight">System Overview</a></li><li><a href="#the-basics" class="table-of-contents__link toc-highlight">The Basics</a><ul><li><a href="#implementation-of-isenabled" class="table-of-contents__link toc-highlight">Implementation of isEnabled</a></li></ul></li><li><a href="#activation-strategies" class="table-of-contents__link toc-highlight">Activation Strategies</a><ul><li><a href="#extension-points" class="table-of-contents__link toc-highlight">Extension points</a></li></ul></li><li><a href="#fetching-feature-toggles-polling" class="table-of-contents__link toc-highlight">Fetching feature toggles (polling)</a></li><li><a href="#client-registration" class="table-of-contents__link toc-highlight">Client registration</a></li><li><a href="#metrics" class="table-of-contents__link toc-highlight">Metrics</a></li><li><a href="#backup-feature-toggles" class="table-of-contents__link toc-highlight">Backup Feature Toggles</a></li></ul></div></div></div></div></main></div></div><footer class="footer footer--dark"><div class="container container-fluid"><div class="row footer__links"><div class="col footer__col"><div class="footer__title">Product</div><ul class="footer__items clean-list"><li class="footer__item"><a class="footer__link-item" href="/">Docs</a></li><li class="footer__item"><a href="https://github.com/Unleash/unleash" target="_blank" rel="noopener noreferrer" class="footer__link-item">Unleash on GitHub<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li><li class="footer__item"><a href="https://github.com/orgs/Unleash/projects/10" target="_blank" rel="noopener noreferrer" class="footer__link-item">Roadmap<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li><li class="footer__item"><a href="https://getunleash.zendesk.com/hc/en-gb" target="_blank" rel="noopener noreferrer" class="footer__link-item">Unleash help center<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li></ul></div><div class="col footer__col"><div class="footer__title">Community</div><ul class="footer__items clean-list"><li class="footer__item"><a href="https://github.com/unleash/unleash/discussions/" target="_blank" rel="noopener noreferrer" class="footer__link-item">GitHub discussions<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li><li class="footer__item"><a href="https://slack.unleash.run/" target="_blank" rel="noopener noreferrer" class="footer__link-item">Slack<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li><li class="footer__item"><a href="https://stackoverflow.com/questions/tagged/unleash" target="_blank" rel="noopener noreferrer" class="footer__link-item">Stack Overflow<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li><li class="footer__item"><a href="https://twitter.com/getunleash" target="_blank" rel="noopener noreferrer" class="footer__link-item">Twitter<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li></ul></div></div><div class="footer__bottom text--center"><div class="margin-bottom--sm"><img src="/img/logo.svg" alt="Unleash logo" class="themedImage_ToTc themedImage--light_HNdA footer__logo"><img src="/img/logo.svg" alt="Unleash logo" class="themedImage_ToTc themedImage--dark_i4oU footer__logo"></div><div class="footer__copyright">Copyright © 2024 Unleash. Built with Docusaurus.</div></div></div></footer></div>
<script src="/assets/js/runtime~main.60bdb37d.js"></script>
<script src="/assets/js/main.3c1b2d68.js"></script>
</body>
</html>