uri-template

Crates.iouri-template
lib.rsuri-template
version0.1.0
created_at2026-01-02 11:15:29.112314+00
updated_at2026-01-02 11:15:29.112314+00
descriptionRFC6570 URI Template library for Rust, with parsing, expansion, compile-time checked macros, and no_std support.
homepagehttps://github.com/gntzh/uri-template
repositoryhttps://github.com/gntzh/uri-template
max_upload_size
id2018382
size9,112
Grant Zhang (gntzh)

documentation

README

uri-template

A Rust Implementation of RFC6570 URI Template with parsing, expansion, compile-time checked macros, and no_std support.

uri-template = { version = "0.1.0", features = ["macros"] }

Features

  • Full support of RFC6570 Level 4 URI Template.
  • Runtime parsing and expansion.
  • Compile-time checked procedural macros.
  • no_std support.

Quick Start

Basic usage:

use uri_template::{HashValues, UriTemplate};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let template = UriTemplate::new("https://example.com/{username}/items{?page,pageSize}")?;
    let mut values = HashValues::new();
    values.insert("username", "foo");
    values.insert("page", 1);
    values.insert("pageSize", 20);
    let uri = template.expand(&values)?;
    assert_eq!(uri, "https://example.com/foo/items?page=1&pageSize=20");
    Ok(())
}

Compile-time checked templates:

use uri_template::{HashValues, uri_template};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let template = uri_template!("https://example.com/{username}/items{?page,pageSize}");
    let mut values = HashValues::new();
    values.insert("username", "foo");
    values.insert("page", 1);
    values.insert("pageSize", 20);
    let uri = template.expand(&values)?;
    assert_eq!(uri, "https://example.com/foo/items?page=1&pageSize=20");
    Ok(())
}

The macro checks template validity at compile time and generates optimized code.

License

Licensed under either of Apache License, Version 2.0 or MIT License at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be dual licensed as above, without any additional terms or conditions.

Commit count: 0

cargo fmt