uri-template-system

Crates.iouri-template-system
lib.rsuri-template-system
version0.1.5
sourcesrc
created_at2023-08-18 23:40:55.471927
updated_at2023-08-24 14:18:42.79071
descriptionURI Template (RFC 6570) Parsing, Expansion and Matching
homepagehttps://github.com/kolektiv/uri-template-system
repository
max_upload_size
id948401
size5,551
Andrew Cherry (kolektiv)

documentation

https://docs.rs/uri-template-system

README

uri-template-system

GitHub docs.rs Crates Continuous Integration Issues Sponsors

URI Templates (RFC6570) are an underrated tool for web programming. They regularise the construction of URIs and related forms, removing the need for ad-hoc string manipulation, and can help provide consistency across complex web applications.

use uri_template_system_core::{ Template, Value, Values };

let template = Template::parse("/hello/{name}/from{/library*}").unwrap();
let values = Values::default()
    .add("name", Value::item("world"))
    .add("library", Value::list(["uri", "template", "system"]));

assert_eq!(
    template.expand(&values).unwrap(),
    "/hello/world/from/uri/template/system"
);

Beyond the scope of the RFC itself, they can also be used (with some judgement) for matching URIs and related forms as well, effectively providing the basis for a routing mechanism which can be driven from the same data as the linking mechanism. No more mismatches between linking and routing.

Scope

This library provides an implementation of URI Templates which complies with the RFC and passes the standard test cases for parsing and expansion.

Future iterations will extend this to provide matching for both single and multiple URI templates, routing based on URI Template matching, and support for strongly-typed template data. See the milestones for the latest progress and for more detailed descriptions of planned features.

Goals

Existing implementations of URI Templates exist for Rust, notably rust-uritemplate and the various forks of that implementation, and an implementation in the broader iri-string library.

This implementation aims to be both more "correct" (the parser is intentionally strict with regards to the RFC, while the existing implementations allow some malformed templates through as valid) and more structured in terms of underlying representation (with the aim of making additional features such as matching more tractable). Performance is also important, and the implementation is roughly on-par with -- or slightly quicker than -- iri-string (the rust-uritemplate derivations have a slightly different programming model, but even allowing for this, they are generally significantly slower).

Benchmarks and RFC-compliance tests (and test harnesses) can be found in the tests directory - as always, benchmarks are indicative but performance under real-world conditions will always vary.

Commit count: 0

cargo fmt