Integrate with REST API
Plain HTTP from any language.
Before you start#
- A client key (
fs_client_…) from the API Keys page of your console. See API keys for how keys differ. - The address of your FlagSwift server, for example
https://flags.example.com. - A flag to read. Create one in the console and turn it on in an environment.
Only client keys belong in an app people can inspect
Server and admin keys can read targeting and rollout data. Use a client key for anything that ships to a browser or a phone.
Your server#
Enter your server address and, if your key covers every environment of the project, the environment to read. The examples below fill in as you type. Nothing is sent anywhere: the values stay in this browser.
Set up#
Environment
bash export FLAGSWIFT_CLIENT_KEY=fs_client_... # from the API Keys pagecurl
bash curl -s -X POST "https://flags.example.com/api/v1/evaluation/client" \ -H "Authorization: Bearer $FLAGSWIFT_CLIENT_KEY" \ -H "Content-Type: application/json" \ -d '{"identifiers":["user-123"],"attributes":{"plan":"pro"}}'fetch
ts const res = await fetch("https://flags.example.com/api/v1/evaluation/client", { method: "POST", headers: { Authorization: `Bearer ${process.env.FLAGSWIFT_CLIENT_KEY}`, "Content-Type": "application/json" }, body: JSON.stringify({ identifiers: ["user-123"], attributes: { plan: "pro" } }), }); const { flags } = await res.json(); // { "new-dashboard": { enabled: true, version: 7 }, ... }Server config
bash # Server or admin key only: the configuration for local evaluation curl -s "https://flags.example.com/api/v1/evaluation/server?mode=config" \ -H "Authorization: Bearer $FLAGSWIFT_SERVER_KEY"
Verify it works#
Before you run your app, check the key, the address and the environment with one request. A client key reads the outcome for one person.
curl -s -X POST "https://flags.example.com/api/v1/evaluation/client" \
-H "Authorization: Bearer $FLAGSWIFT_CLIENT_KEY" \
-H "Content-Type: application/json" \
-d '{"identifiers":["user-123"]}'A 200 response with your flags means everything is wired up. If it fails, Troubleshooting lists the usual causes.