Publish toggle with REST API
Every FeatureProbe feature begins as an REST API. You can perform any operation in the FeatureProbe product through the REST API.
Suppose we need to implement the following scenarios through the REST API:
- Create a new toggle
- Open and publish this toggle
Create Access Token
All REST API resource access uses Access Token for authentication, no other authentication mechanisms are supported.
1、Log in to the FeatureProbe demo platform. If you log in for the first time, please enter your email address. You can continue to use your email to access your data in the future.
2、Click "Settings" at the top of the page,Then select "Access tokens" on the left ,Click + Token
button to create a new Access Token.
- Fill in the name.
- Select the "Owner" role.
- Click on
Create
.
3、Copy and save the TOKEN. After the Access Token is successfully created, we need to copy and save it in the TOKEN, which will not be viewable later.
Create Toggle
By default, FeatureProbe will create a My_Project project and an online environment under the project. We will demonstrate to create a "New Feature" toggle under this project.
Replace ${API_ACCESS_TOKEN} in the command below with the TOKEN saved above.
curl -i 'https://featureprobe.io/api/projects/My_Project/toggles' \
-X 'POST' \
-H 'Authorization: ${API_ACCESS_TOKEN}' \
-H 'Content-Type: application/json' \
--data-raw '{
"name": "New Feature",
"key": "new_feature",
"desc": "This is a feature control toggle.",
"tags": [],
"clientAvailability": true,
"returnType": "boolean",
"variations": [{
"value": "false",
"name": "Close",
"description": "Close new feature."
}, {
"value": "true",
"name": "Open",
"description": "Open new feature."
}],
"disabledServe": 0,
"permanent": false
}'
Whether the verification is successful
Open and publish
The toggle creates a default disabled state. Next, we will turn on this toggle through the REST API.
Replace ${API_ACCESS_TOKEN} in the command below with the TOKEN saved above.
curl -i 'https://featureprobe.io/api/projects/My_Project/environments/online/toggles/new_feature/targeting' \
-X 'PATCH' \
-H 'Authorization: ${API_ACCESS_TOKEN}' \
-H 'Content-Type: application/json' \
--data-raw '{
"comment": "Open toggle.",
"disabled": false,
"content": {
"defaultServe": {
"select": 1
}
}
}'
Whether the verification is successful