Routing with URI Templates (RFC6570)

35 views
Skip to first unread message

Neil Brewster

unread,
Jun 18, 2013, 12:10:51 PM6/18/13
to res...@googlegroups.com
Does anyone know of a REST request router with built-in support for URI Templates (per RFC 6570)? Using restify it seems possible to do simple string expansion (https://tools.ietf.org/html/rfc6570#section-3.2.2). I'm specifically interested in reserved expansion (https://tools.ietf.org/html/rfc6570#section-3.2.3) for an implementation where I'm using ":" to separate components of a URI. For example, I want to support a request like:
where {id} might look like "abc:def:ghi".

A restify handler like:
  server.get('/some/resource/:name', respond);
will not match a request like:
It will instead respond with:
{"code":"ResourceNotFound","message":"/some/resource/abc:def:ghi does not exist"}

Note I am explicitly NOT urlencoding the ":" in the request; in my implementation the ":" character has meaning as a delimiter. As far as I can tell this is valid per the explanations in https://tools.ietf.org/html/rfc3986#section-2.2 and https://tools.ietf.org/html/rfc3986#section-3.3.

I can get it to work if I use a regexp handler like:
  server.get(/\/another\/resource\/(.*)/, regexp_respond);
... which might be my only option.

Is anyone aware of a REST request router that will support (for example) the "{+var}" URI Template syntax, and/or other parts of RFC6570?

There are implementations out there like https://github.com/fxa/uritemplate-js, but that seems to be in the wrong direction (it will expand a URI based on a URI Template, but it won't map/match/route request URIs against templates).

I apologize if I'm missing something fundamental here - I'm new to this space...

neil.
Reply all
Reply to author
Forward
0 new messages