uri-template

2019-08-13

An implementation of the URI Template proposed standard draft version 01.

Upstream URL

common-lisp.net/project/uri-template/release/uri-template-latest.tgz

Author

Vladimir Sedach <vas@oneofus.la>

License

LGPL-3.0-or-later
README
uri-template is an implementation of the URI Template proposed standard draft version 01 (https://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)) #Uhttps://www.example.com/widget/{foo}/parts) => "https://www.example.com/widget/1/parts" Template destructuring: (uri-template-bind (#Uhttps://www.example.com/{part}/{number}) "https://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}) "https://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 "https://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: https://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: https://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: https://mailman.common-lisp.net/listinfo/uri-template-devel The author, Vladimir Sedach, can be contacted at: vas@oneofus.la uri-template is distributed under the terms of the GNU Lesser General Public License, version 3 or any later version. See the files COPYING and COPYING.LESSER, included with the distribution, or https://www.gnu.org/licenses/

Dependencies (4)

  • cl-ppcre
  • fiveam
  • flexi-streams
  • named-readtables
  • GitHub
  • Quicklisp