hannesg / uri_template

A URI template library for ruby.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Extending beyond RFC6570

dblock opened this issue · comments

We use uri_template in Hyperclient, https://github.com/codegram/hyperclient. Most of the time you have an URI template in some resource and you expand it. For example a link could be http://example.com/widgets/{id}. However sometimes you have things like http://example.com/widgets/{?sort,size,page,offset} which is rather annoying and ends up being copy-pasted all over the place, or usually just forgotten by the API developers.

In code this is used like so:

client.widgets(id: 1)
client.widgets(sort: 'created_at', size: 10)
...

We would like to generally be able to omit these parameters, but still include them in the resulting URI. So a template like http://example.com/widgets{?size} could actually be expanded with client.widgets(sort: 'created_at'), basically using the template as a hint as opposed to a hard requirement.

Furthermore we'd like to fail when a required parameter is missing. Anything that's not a query parameter should probably be required.

See codegram/hyperclient#84.

Generally just looking for feedback. Is an implementation like this in scope of this library? If so I would probably refactor rfc6570.rb somewhat into a generic base, the old rfc6570 implementation and a variation described above.

@hannesg This keeps coming up, maybe care to comment? Thanks!