Skip to main content

compile_uri_template

Function compile_uri_template 

Source
pub fn compile_uri_template(
    template: &str,
) -> Result<(HashSet<String>, Regex), KERIError>
Expand description

Compile the given URI template string into a pattern matcher

This function can be used to construct custom routing engines that iterate through a list of possible routes, attempting to match an incoming request against each route’s compiled regular expression.

Each field is converted to a named group, so that when a match is found, the fields can be easily extracted using the capture groups.

This function does not support the more flexible templating syntax used in the default router. Only simple paths with bracketed field expressions are recognized. For example:

/ /books /books/{isbn} /books/{isbn}/characters /books/{isbn}/characters/{name}

Also, note that if the template contains a trailing slash character, it will be stripped in order to normalize the routing logic.

§Arguments

  • template - The template to compile. Note that field names are restricted to ASCII a-z, A-Z, and the underscore character.

§Returns

  • (template_field_names, template_regex)