Skip to content

Latest commit

 

History

History
65 lines (54 loc) · 3.39 KB

documentation.md

File metadata and controls

65 lines (54 loc) · 3.39 KB

Documentation

HTTP Requests

GET /config

Status code: 200
Body: List of all configuration fields
Example: curl localhost:8081/config/


GET /config/<configuration field>

Status code: 200 if the field exists, otherwise 404
Body: The value of the specified configuration field
Example: curl localhost:8081/config/logfile


PUT /config/<configuration field> <new value>

Status code: 200 if the new value has been set, 404 if the field doesn't exist or 400 if the new value is invalid
Body: An error message if the new value is invalid
Example: curl -X PUT localhost:8081/config/filename -d "file.txt"

Macro attributes

Attribute name Value Position Usage Effect
path String struct #[choices(path = "myconfig")] sets the root path of the configuration HTTP service
message String struct #[choices(message = "Welcome!")] sets the root path message (not available with JSON)
json struct #[choices(json)] requests and responses content is in json
on_set Expression field #[choices(on_set = print_value)] invokes an expression in the form expr(&v) where v is the new value (note: the old value is replaced after this call returns)
skip field #[choices(skip)] do not treat this field as a 'configuration field'
hide_get field #[choices(hide_get)] do not generate the HTTP GET for this field
hide_put field #[choices(hide_put)] do not generate the HTTP PUT for this field
validator Expression field #[choices(validator = check_value)] invokes an expression in the form expr(&v) -> ChoicesResult<()> where v is the new value; the field's value is updated only if the result is Ok
rw_lock struct #[choices(rw_lock)] generates code to hold the configuration object in an Arc<RwLock<>> instead of an Arc<Mutex<>>.

Supported configuration field types

Type Text Json Notes
bool ✔️ ✔️
char ✔️ ✔️
i128 ✔️ ✔️
i16 ✔️ ✔️
i32 ✔️ ✔️
i64 ✔️ ✔️
i8 ✔️ ✔️
isize ✔️ ✔️
u128 ✔️ ✔️
u16 ✔️ ✔️
u32 ✔️ ✔️
u64 ✔️ ✔️
u8 ✔️ ✔️
usize ✔️ ✔️
f32 ✔️ ✔️
f64 ✔️ ✔️
String ✔️ ✔️
Option<T> ✔️ ✔️ T must be supported
user defined Type and Type<T, ...> ✔️ user must implement the traits ChoicesInput and ChoicesOutput
any Type and Type<T, ...> ✔️ type must be serializable and deserializable with serde