|(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.
Three functions are provided.
thing : any/c
Checks whether a value is (a) a string that (b) adheres to the official syntax of URI Template.
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:
string A (Racket) string (including the empty string)
list A (Racket) list of (Racket) strings
associative array A (Racket) list of (Racket) lists of (Racket) strings, each element of which has exactly two members. (Think assoc.)
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?).
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?).