juretta.com

URI-Template gem released

March 15, 2008
Tags: ANTLR PEG Ragel Ruby Rubygems Treetop

URITemplate is a parser for URI Templates as defined in the URI Template specification (http://bitworking.org/projects/URI-Templates).

URI Templates are strings that contain embedded variables that are transformed into URIs after embedded variables are substituted. This specification defines the structure and syntax of URI Templates.

A simple example shows the usage: http://example.com/search?q={searchTerms}&num={count} can be expanded to

http://example.com/search?q=hello%20world&num=5
http://example.com/search?q=ruby&num=100

by supplying different variables for searchTerms and count.

http://bitworking.org/projects/URI-Templates/ is the homepage of the current draft. http://code.google.com/p/uri-templates/ hosts the current reference implementation in Python.

Install the Ruby gem:

macbook-pro:~ stefan$ sudo gem install uri-templates
Treetop - go look at it

After playing around with Ragel and ANTLR I decided to use the excellent Treetop (Parsing expression grammar implementation) to implement the URI template specification. Although the draft explicitly states that you do not need a full full-fledged parser, Treetop made it really easy to implement just that.

Get the source:

macbook-pro:~ stefan$ git clone git://scm.juretta.com/uri-templates.git

blog comments powered by Disqus

About

juretta.com is the personal workspace of Stefan Saasen. More about this site can be found in the „About“ section.

Share!

Latest links  RSS  

More...