uri-template:   A template language for URIs (IETF RFC 6570)
1 Library interface

uri-template: A template language for URIs (IETF RFC 6570)

Jesse Alama <[email protected]>

 (require uri-template) package: uri-template

This package aims to implement RFC 6570, URI Template. That RFC specifies a little pattern langauge for specifying classes of URIs. URIs may match a URI Template, and given an assignment of values to variables, one may expand a URI Template, which yields a URI. All those fussy details about precisely what characters are allowed in URIs (does this character, here, need to be percent-escaped?) are carefully observed.

1 Library interface

Three functions are provided.


(uri-template? thing)  boolean?

  thing : any/c

Checks whether a value is (a) a string that (b) adheres to the official syntax of URI Template.


(value? thing)  boolean?

  thing : any/c

Checks whether a (Racket) value is an acceptable value for a (URI Template) variable. There are three kinds of acceptable values: strings, lists, and assocative arrays. These work out, in Racket, to:


(assignment? assn)  boolean?

  assn : any/c

Checks whether a value is an assignment (of values to variables). Assignments are supposed to be hashes whose keys are strings and whose values are acceptable values (in the sense of value?).


(expand-template template assignment)  string?

  template : string?
  assignment : assignment?

Given a string and an assignment, apply the template. The result is a string.

Naturally, the template should adhere to the syntax of URI Template; otherwise, an error (of type exn:fail?) will be thrown.

References to undefined variables do not lead to an error. Such variables will be silently ignored, according to RFC 6570.

Attempts to do syntactically unobjectionable but semantically bad things, such as applying the max-length modifier—something that makes sense only for strings—to a list or associative array, will lead to error (of type exn:fail:contract?).