[][src]Crate rfc6570_level_2

To use this library, instantiate an UriTemplate with a relevant string. From here, the result can be "discarded" if only validation of the input string is needed, or a list of contained expressions or variables can be retrieved with expressions() or variables(). Finally, the URI template can be expanded by called expand() with a HashMap<&str, &str> of variables and values.

use rfc6570_level_2::UriTemplate;

let template = UriTemplate::new("https://example.com/{resource}/{+id}{#field}")?;

// What variables are available?
let variables: Vec<&str> = template.variables().collect();
assert_eq!(variables, vec!["resource", "id", "field"]);

let var_map = [
    ("resource", "user"),
    ("id", "5"),
    ("field", "email"),

// Expand the template
let uri = template.expand(&var_map);
assert_eq!(uri, "https://example.com/user/5#email");



A template URI validated against RFC6570 Level 2.