QuickStart: Explore it with Node.js

This quickstart guide will help you deploy the FE&R Decision API locally and interact with it using Node.js. You'll learn how to make API calls, manage visitor sessions, and implement feature flag.

Prerequisites

  • Node.js 14.x or higher

  • Docker and Docker Compose installed

  • FE&R Account with Environment ID and API Key

Step 1: Start the Decision API

Quick Start with Docker Compose

  1. Create a project directory:

mkdir flagship-quickstart
cd flagship-quickstart
  1. Create a docker-compose.yml file:

version: "3.9"

services:
  redis:
    image: redis:7-alpine
    container_name: flagship-redis
    ports:
      - "6379:6379"
    volumes:
      - redis-data:/data
    restart: unless-stopped

  decision-api:
    image: flagshipio/decision-api:latest
    container_name: flagship-decision-api
    ports:
      - "8080:8080"
    environment:
      ENV_ID: YOUR_ENV_ID
      API_KEY: YOUR_API_KEY
      LOG_LEVEL: debug
      CACHE_TYPE: redis
      CACHE_OPTIONS_REDISHOST: redis:6379
    depends_on:
      - redis
    restart: unless-stopped

volumes:
  redis-data:
    driver: local

networks:
  default:
    name: flagship-demo
  1. Replace credentials:

Replace YOUR_ENV_ID and YOUR_API_KEY with your actual FE&R credentials from https://app2.abtasty.com

  1. Start the services:

Step 2: Set Up Your Node.js Project


REST APIs

The Decision API provides simple REST endpoints. Below are practical examples of how to use each endpoint.

Start an HTTP Session

In Flagship, a visitor "session" is simply making API calls with a unique visitor ID. The visitor ID should be consistent across requests to enable features like Experience Continuity.

Example: Fetch Campaigns for a Visitor

Create examples/get-campaigns.js:

Run it:

Example: Activate a Campaign

When a visitor sees a variation, you must activate it to send analytics data to Flagship.

Create examples/activate-campaign.js:

Run it:

Run a Feature Flag

Feature flags allow you to control features and A/B test variations. The /v2/flags endpoint provides a flag-oriented view of your campaigns.

Example: Get Feature Flags

Create examples/get-flags.js:

Run it:

Last updated

Was this helpful?