uri-template:   A template language for URIs (IETF RFC 6570)
1 Library interface
uri-template?
value?
assignment?
expand-template
variables-of
8.12

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

Jesse Alama <jesse@lisp.sh>

 (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🔗ℹ

procedure

(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.

procedure

(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:

procedure

(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?).

procedure

(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?).

procedure

(variables-of template)  (listof string?)

  template : string?

Find all variables occuring in a template. The result is a list of unique strings.

No promises is made about the order of the variables appearing in the result. The first variable appearing in the template might occur at the beginning, middle, or end of the list.

As with expand-template, the given string should adhere to the syntax of URI Template; otherwise, an error (of type exn:fail?) will be thrown.