Urchin.URITemplate (Urchin v0.1.0)

Copy Markdown View Source

Minimal RFC 6570 URI template matching used to route resources/read requests to a declared resource_template.

Supports level-1 {var} expressions. A bare {var} matches a single path segment (no /); {+var} and {var*} match across segments. This is sufficient for the common resource-template patterns; full RFC 6570 expansion is intentionally not implemented.

Summary

Functions

Compiles a URI template into a {regex, var_names} pair for repeated matching.

Matches uri against template, returning extracted variables on success.

Functions

compile(template)

@spec compile(String.t()) :: {Regex.t(), [String.t()]}

Compiles a URI template into a {regex, var_names} pair for repeated matching.

match(template, uri)

@spec match(String.t() | {Regex.t(), [String.t()]}, String.t()) ::
  {:ok, %{required(String.t()) => String.t()}} | :error

Matches uri against template, returning extracted variables on success.

Accepts either a raw template string or a precompiled {regex, vars} tuple.