Struct uritemplate::UriTemplate [] [src]

pub struct UriTemplate { /* fields omitted */ }

The main struct that processes and builds URI Templates.

Methods

impl UriTemplate
[src]

Creates a new URI Template from the given template string.

Example

let t = UriTemplate::new("http://example.com/{name}");

Sets the value of a variable in the URI Template.

Example

let mut t = UriTemplate::new("{name}");
t.set("name", "John Smith");

This function returns the URITemplate so that the set() calls can be chained before building.

let uri = UriTemplate::new("{firstname}/{lastname}")
    .set("firstname", "John")
    .set("lastname", "Smith")
    .build();
assert_eq!(uri, "John/Smith");

Deletes the value of a variable in the URI Template. Returns true if the variable existed and false otherwise.

Example

let mut t = UriTemplate::new("{animal}");
t.set("animal", "dog");
assert_eq!(t.delete("house"), false);
assert_eq!(t.delete("animal"), true);

Deletes the values of all variables currently set in the URITemplate.

Expands the template using the set variable values and returns the final String.

Example

let mut t = UriTemplate::new("{hello}");
t.set("hello", "Hello World!");
assert_eq!(t.build(), "Hello%20World%21");