Expand description
Easy HTTP configuration library.
choices
is a library that lets you expose your application’s configuration
over HTTP with a simple struct!
Examples
Given the following code:
use choices::Choices;
use lazy_static::lazy_static;
use std::sync::{Arc, Mutex};
#[derive(Choices)]
struct Config {
debug: bool,
id: Option<i32>,
log_file: String,
}
lazy_static! {
static ref CONFIG: Arc<Mutex<Config>> = {
Arc::new(Mutex::new(Config {
debug: false,
id: Some(3),
log_file: "log.txt".to_string()
}))
};
}
#[tokio::main]
async fn main() {
CONFIG.run((std::net::Ipv4Addr::LOCALHOST, 8081)).await;
}
You can see all configuration fields at localhost:8081/config
and the individual fields’ values at localhost:8081/config/<field name>
A field’s value can be changed with a PUT
, for instance
curl -X PUT localhost:8081/config/debug -d "true"
.
More examples on github.
Documentation
Check out the documentation on github.
Re-exports
pub use crate::error::ChoicesError;
pub use crate::error::ChoicesResult;
pub use crate::serde::ChoicesInput;
pub use crate::serde::ChoicesOutput;
Modules
Re-export of bytes
Handles errors.
Serializes and deserializes fields’ value.
Re-export of warp
Traits
A trait to manage the http server responsible for the configuration.