Skip to content

Binding API

Workers access Flagship through a binding that you add to your Wrangler configuration file. The binding field sets the variable name you use in your Worker code.

JSONC
{
"flagship": {
"binding": "FLAGS",
"app_id": "<APP_ID>",
},
}

Replace <APP_ID> with the app ID from your Flagship app. If you have not created an app yet, refer to the Get started guide. With this configuration, the binding is available as env.FLAGS. Refer to Configuration for additional options such as binding to multiple apps.

The binding provides type-safe methods for evaluating feature flags. If an evaluation fails or a flag is not found, the method returns the default value you provide.

JavaScript
export default {
async fetch(request, env) {
const enabled = await env.FLAGS.getBooleanValue("new-feature", false, {
userId: "user-42",
});
return new Response(enabled ? "Feature on" : "Feature off");
},
};

The binding has the type Flagship from the @cloudflare/workers-types package.