uri-template is an implementation of the URI Template proposed
standard draft version 01
(http://tools.ietf.org/html/draft-gregorio-uritemplate-01) as a reader
macro, used for both creating and parsing URIs.

Although uri-template does not implement the operators introduced in
the 02 and later drafts of the URI Template standard, it does allow
arbitrary Lisp expressions in template placeholders, which gives
simpler and more powerful templates.

Example use:

Template interpolation:

(let ((foo 1))
  #Uhttp://www.example.com/widget/{foo}/parts)

=> "http://www.example.com/widget/1/parts"


Template destructuring:

(uri-template-bind (#Uhttp://www.example.com/{part}/{number})
    "http://www.example.com/widget/1"
  (list part (parse-integer number) %uri-host))

=> ("widget" 1 "www.example.com")


Template desctructuring also binds several handy standard components
to anaphoric variables:

(uri-template-bind (#U{uri})
    "http://user@www.foo.com:8080/dir/abc?bar=baz&xyz=1#hash"
  (list %uri-scheme          =>     ("http"
        %uri-authority               "user@www.foo.com:8080"
        %uri-user                    "user"
        %uri-host                    "www.foo.com"
        %uri-port                    "8080"
        %uri-path                    "/dir/abc"
        %uri-directory               "/dir/"
        %uri-file                    "abc"
        %uri-query                   "bar=baz&xyz=1"
        %uri-fragment                "hash"
        %uri-head                    "http://user@www.foo.com:8080"
        %uri-tail))                  "/dir/abc?bar=baz&xyz=1#hash")

More examples can be found in the uri-template-test.lisp file.

uri-templates can be enabled by calling enable-uri-template-syntax, or
by merging or using the uri-template:uri-template readtable via the
named-readtables library
(http://common-lisp.net/project/named-readtables/)

Function reference:

enable-uri-template-syntax (function)
  Binds the #U dispatch character to read a URI template.

read-uri-template (function)
  A function suitable for inserting into the readtable so you can
  read URI templates from your own dispatch character.

uri-decode? (special variable)
  Controls whether URI decoding/unescaping is done on the templated
  value when destructuring. True by default.

uri-encode? (special variable)
  Controls whether URI encoding/escaping is done on the templated value.
  True by default.

uri-decode (function)
  Decodes URI encoded/escaped characters in the given string.

uri-encode (function)
  URI encodes/escapes the given string.

uri-template (symbol)
  The car of the list that the URI template reader produces. A
  function or macro.
  This symbol also names the named-readtables readtable that provides
  the #U dispatch macro.

uri-template-bind (macro)
  Binds URI template placeholders (which must be symbols) in given
  URI, as well as attempting to bind a set of standard URI components to
  their respective parts of the given URI. Body executes only if all
  explicitly specified URI template placeholders can be bound.

uri-template works with Parenscript to provide template interpolation
for JavaScript. To enable this functionality, load Parenscript before
compiling uri-template (you might need to re-compile if you have
previously loaded uri-template without first loading
Parenscript). Note that destructuring is currently unsupported for
Parenscript.

For more information about uri-template, see the project homepage:
http://common-lisp.net/project/uri-template/

The uri-template mailing list is uri-template-devel@common-lisp.net.
Any questions, bug reports and patches are welcome. You can subscribe
by visiting:
http://common-lisp.net/cgi-bin/mailman/listinfo/uri-template-devel

The author, Vladimir Sedach, can be contacted at vsedach@gmail.com.

The code is licensed under the LLGPL (see the file COPYING included
with the distribution for details), except for the unit tests, which
are in the public domain.