Accessing Flags through REST API.

One of the main features of Switchr is accessing the feature flags through REST APIs.
For security purposes in order to get the feature flag value from api, a Token has to be generated and sent through the headers.

Steps to generate a auth token

  • Navigate to Dashboard Page.
  • Open the project that has feature flag that needs to be accessed.
  • Click on the API Button.
  • A dialog box will appear, Click on Generate Token Button.
  • A token with validity of 120 days will be generated.
    Example Token -
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MzYwNzI3MDQsIlVpZCI6IiIsIlR5cGUiOiJhcGktdG9rZW4iLCJFbWFpbCI6IiIsIlJvbGUiOjAsIldasdasI6ImRkNjFmOTlkLWU4MGEtNDhlYS04ODA2LWNmN2VjNmNjNTM5NyJ9.WGpNELEtE-RswhiGAdBBmHO3Yh1IyOW8ykMMRWiDj_E

Fetching data through API.

  • In order to fetch data, following endpoint has to be used -
GET https://dev-server.live:8020/api/get/<FLAG_NAME>

Params

  • FLAG_NAME : Name of the feature flag, Required

Headers

  • token : Authorization token generated above, Required

Example Request

Assume, requesting a flag named "create_enable" with its value as "true"

curl -X GET  http://localhost:8020/api/get/create_enable \
--header 'token:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MzYwNzI3MDQsIlVpZCI6IiIsIlR5cGUiOiJhcGktdG9rZW4iLCdaskdjkasIiIsIlJvbGUiOjAsIlBpZCI6ImRkNjFmOTlkLWU4MGEtNDhlYS04ODA2LWNmN2VjNmNjNTM5NyJ9.WGpNELEtE-RswhiGAdBBmHO3Yh1IyOW8ykMMRWiDj_E'

Example Success Response

{"flag":"true"} 
  • Response body has a field called "flag" which has the value of the flag

Example Failure Response

{"message":"Record not found","success":false}