Crates.io | urltemplate |
lib.rs | urltemplate |
version | 0.1.5 |
source | src |
created_at | 2019-02-02 12:08:05.865611 |
updated_at | 2019-03-12 07:03:44.137435 |
description | Lightweight URL templates. Master URLs with placeholders! |
homepage | https://github.com/vladignatyev/rust-urltemplate |
repository | https://github.com/vladignatyev/rust-urltemplate.git |
max_upload_size | |
id | 112171 |
size | 12,285 |
Convert URL template containing placeholders into url.
Whenever you need to turn https://example.com/?utm_source={source}&key2={value2}
into URL like https://example.com/?utm_source=github&key2=
Core idea is to have minimalistic and comfortable to use placeholders for http/https URLs. Comfortable means to be easily used in any web-related project, UTF-safe.
extern crate urltemplate;
use urltemplate::UrlTemplate;
use std::collections::HashMap;
let mut params = HashMap::new();
params.insert("source".to_string(), "url-template-crate-❤".to_string());
let url_with_placeholders = UrlTemplate::from("https://www.mozilla.org/?utm_source={source}");
let url_as_string = url_with_placeholders.substitute_str(¶ms).expect("valid url");
let url_as_url = url_with_placeholders.substitute(¶ms).expect("valid url");
assert_eq!(url_as_string, "https://www.mozilla.org/?utm_source=url-template-crate-❤");
assert_eq!(url_as_url.query(), Some("utm_source=url-template-crate-❤"));
url
crate is required)