Crates.io | vexilla_client |
lib.rs | vexilla_client |
version | 1.0.0 |
source | src |
created_at | 2021-02-12 23:48:04.158537 |
updated_at | 2024-05-09 06:34:46.514303 |
description | A Rust client for the Vexilla Feature Flag System |
homepage | |
repository | |
max_upload_size | |
id | 354424 |
size | 958,088 |
This is the Rust client library for Vexilla, a static file-based VCS-native feature flag system.
To get started is easy. Follow these steps to get started with integration.
Add the client to your imports.
vexilla_client = "1.x.x"
You will need to create a Client within your app. This optionally takes in the custom_instance_hash
for use with gradual rollout as well as Selective features.
After creation, call sync_flags_blocking
. This can be chained from the constructor since it returns the client instance.
Important Note: All methods that make HTTP requests take in a callback for the request itself. This allows you to use your existing dependencies or standard library methods to keep this bundle smaller and less opinionated.
let mut client = VexillaClient::new("dev", "https://BUCKET_NAME.s3-website-AWS_REGION.amazonaws.com", user_id);
client.sync_manifest(|url| reqwest::blocking::get(url).unwrap().text().unwrap());
client
.sync_flags("Scheduled", |url| {
reqwest::blocking::get(url).unwrap().text().unwrap()
})
.unwrap();
Use the created client to check if a feature Should
be on.
let should_show_feature = client.should(FEATURE_NAME)
let environment = "dev"
let server_host = "https://BUCKET_NAME.s3-website-AWS_REGION.amazonaws.com"
let user_id = "b7e91cc5-ec76-4ec3-9c1c-075032a13a1a"
let mut client = VexillaClient::new(environment, server_host, user_id);
client.sync_manifest(|url| reqwest::blocking::get(url).unwrap().text().unwrap());
client
.sync_flags("Scheduled", |url| {
reqwest::blocking::get(url).unwrap().text().unwrap()
})
.unwrap();
if client.should(FEATURE_NAME) {
// Do the thing
}
Feature flags are useful for enabling or disabling parts of your application without having to redeploy. In some cases, such as mobile applications, the redeploy could take up to a week.
See more about them here:
Feature Flags are also a fundamental building block for things such as A/B testing.
The process is simple but has several steps to get up and running. Please see our in-depth guides in our documentation.
pub fn new( environment: &'static str, base_url: &'static str, instance_id: &'static str) -> VexillaClient
Returns a new instance of the Vexilla client
environment &'static str
: The name or ID of the environment you are targeting. This will be used in the lookups of flags and their config.
base_url &'static str
: The base URL where your JSON files are stored. When fetching flags Vexilla will append the coerced file name to the url. No trailing slash.
instance_id &'static str
: The ID, often for a user, to use by default for determining gradual flags and selective flags.
pub fn get_manifest(&self, fetch: Callback) -> Result<Manifest>
Fetches the manifest file for facilitating name->id lookups. Does not set the value on the client. You would need to call set_manifest
after. Alternatively, you can use sync_manifest
to do both steps with less code.
fn(url: &str) -> String
: A callback that is passed the url of the manifest file. You can bring your own http request library.pub fn set_manifest(&mut self, manifest: Manifest)
Sets a fetched manifest within the Client instance.
Manifest
: The manifest file to persist into the client. Usually fetched via get_manifest
.pub fn sync_manifest(&mut self, fetch: Callback)
Fetches and sets the manifest within the client to facilitate name->Id lookups.
fn(url: &str) -> String
: A callback that is passed the url of the manifest file. You can bring your own http request library.pub fn get_flags(&self, file_name: &str, fetch: Callback) -> VexillaResult<FlagGroup>
Fetches the flags for a specific flag_group. Can use the ID or the name of the group for the lookup.
file_name &str
: The Name or ID of the flag group you would like to fetch.
fetch fn(url: &str) -> String
: A callback that is passed the url of the flag group file. You can bring your own http request library.
pub fn set_flags(&mut self, group_id: &str, flags: FlagGroup)
Sets a fetched flag group within the Client instance.
group_id &str
: The ID or name of the flag group that you would like to set.
flags FlagGroup
: The collection of flags you would like to set. Typically from a get_flags
call. sync_flags
wraps both functions to streamline the process.
Fetches and sets the flag group within the client to facilitate name->Id lookups.
file_name &str
: The Name or ID of the flag group you would like to fetch.
fetch fn(url: &str) -> String
: A callback that is passed the url of the flag group file. You can bring your own http request library.
Checks if a toggle, gradual, or selective flag should be enabled. Other methods exist for other flag types, such as value.
group_id &str
: The ID or name of the flag group that you would like to check.
feature_name &str
: The ID or name of the feature flag that you would like to check.
Similar to the should
method, but allows passing a custom string for use in the same way custom_hash_id
is used from the contructor. This can be especially useful for Selective flags that target groups instead of individual user IDs.
group_id &str
: The ID or name of the flag group that you would like to check.
feature_name &str
: The ID or name of the feature flag that you would like to check.
custom_id &str
: The custom string you would like to evaluate in a gradual check or selective check.
Similar to the should
method, but allows passing a custom integer for use in the same way custom_hash_id
is used from the contructor. This can be especially useful for Selective flags that target groups instead of individual user IDs.
group_id &str
: The ID or name of the flag group that you would like to check.
feature_name &str
: The ID or name of the feature flag that you would like to check.
custom_id i64
: The custom integer you would like to evaluate in a gradual check or selective check.
Similar to the should
method, but allows passing a custom float for use in the same way custom_hash_id
is used from the contructor. This can be especially useful for Selective flags that target groups instead of individual user IDs.
group_id &str
: The ID or name of the flag group that you would like to check.
feature_name &str
: The ID or name of the feature flag that you would like to check.
custom_id f64
: The custom float you would like to evaluate in a gradual check or selective check.
Gets a string value based on environment. Can be useful for things like pricing and subscription plans.
group_id &str
: The ID or name of the flag group that you would like to check.
feature_name &str
: The ID or name of the feature flag that you would like to check.
default &str
: The default string value if the flag is off via scheduling or cannot be fetched.
Gets an integer value based on environment. Can be useful for things like pricing and subscription plans.
group_id &str
: The ID or name of the flag group that you would like to check.
feature_name &str
: The ID or name of the feature flag that you would like to check.
default i64
: The default integer value if the flag is off via scheduling or cannot be fetched.
Gets a float value based on environment. Can be useful for things like pricing and subscription plans.
group_id &str
: The ID or name of the flag group that you would like to check.
feature_name &str
: The ID or name of the feature flag that you would like to check.
default f64
: The default float value if the flag is off via scheduling or cannot be fetched.
We have created a tool to generate types for usage in your code. It will crawl your JSON structures and create consts or enums to help prevent typos and other "magic string" related issues. You just need to pass the URL of the JSON file where it is hosted.
To use the tool, you can run it directly from NPM.
npx vexilla types rust REMOTE_JSON_URL
You can also use a precompiled binary for your platform. This install script will automatically choose the right binary for you:
curl -o- -s https://raw.githubusercontent.com/vexilla/vexilla/main/install.sh | bash
The install script also accepts a target install path:
curl -o- -s https://raw.githubusercontent.com/vexilla/vexilla/main/install.sh | bash -s -- -b /usr/local/bin/
If you prefer to download the binary manually you can get it from the releases section in Github, https://github.com/vexilla/vexilla/releases
Have you run into a bug? Is there a feature you feel is missing? Feel free to create a GitHub Issue.
Another way to get support or help is to reach out in our Discord community.
Would you like to contribute to this client SDK? There are many ways you can help. Reporting issues or creating PRs are the most obvious. Helping triage the issues and PRs of others would also be a huge help. Being a vibrant member of the community on Discord is another way to help out.
If you would like to contribute to the app, docs, or other parts of the project, please go see our Contribution Guide.
We would love to add your company's logo to our usage section on the website. Please submit your name and logo url in this issue.
No sponsors yet. This could be a link and icon for your company here.
Current Vexilla code is released under a combination of two licenses, the Business Source License (BSL) and the MIT License.
Please see the License file for more info.