Expand description
Library to provide functions and structures to work with rede placeholders.
It’s based on an execution flow with three steps:
- Extract the request’
Placeholders. - Use a
Resolverwith differentValuePickerto identify the values to replace each placeholder. - Pass the placeholders and the resolved values to the
Rendererto create a new request.
§Example
let toml = r#"
http = { url = "http://localhost:8080/{{api_version}}/example/{{id}}", method = "GET" }
query_params = { token = "{{API_TOKEN}}" }
variables = { api_version = "v1" }
"#;
let request = rede_parser::parse_request(toml).unwrap();
// find placeholders
let placeholders = (&request).into();
// identify values, as the resolver uses the variables picker, it should be dropped before the render step
let ph_values = {
let resolver = Resolver::new()
.add_picker(Box::new(EnvVarPicker))
.add_picker(Box::new(VariablesPicker::new(&request.variables)));
resolver.resolve(&placeholders)
};
// render new request
let renderer = Renderer::new(&placeholders, ph_values);
let rendered = renderer.render(request)?;
assert_eq!(rendered.url, "http://localhost:8080/v1/example/{{id}}");
assert_eq!(rendered.query_params[0].1, "token_from_env_var".to_string());Re-exports§
pub use value_picker::ValuePicker;
Modules§
- value_
picker - Module containing the
ValuePickertrait and some pickers provided by the crate. In case that some custom picker is required, the trait can be implemented and used in theResolverlike those provided.
Structs§
- Placeholder
Values - Wrapper over the resolved values for the placeholders. You can directly access its internal
valuesor use the convinient methods to ease access to its content. - Placeholders
- The
Placeholdersstruct analyzes a request and extracts all the placeholders from its parts. - Renderer
- A renderer is responsible for rendering a request using the placeholders and values provided.
It should be used with
renderto replace the placeholders with the values in the request. - Resolver
- Uses a list of
ValuePickerto resolve the value ofPlaceholders.