Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional fragments depending on other fragments #9

Open
andrewpthorp opened this issue Aug 21, 2013 · 5 comments
Open

Optional fragments depending on other fragments #9

andrewpthorp opened this issue Aug 21, 2013 · 5 comments

Comments

@andrewpthorp
Copy link
Collaborator

I would be more than willing to implement this, but I was wondering if it's desired or if it's already possible:

Let's say, you have the following template:

tpl = URITemplate.new(:colon, 'http://some.api.com[/:optional[/:optional2]]')

:optional2: would only be added if :optional1 existed. In other words:

tpl.expand(optional1: 'foo', optional2: 'bar')
# => http://some.api.com/foo/bar

tpl.expand(optional1: 'foo')
# => http://some.api.com/foo

tpl.expand(optional2: 'bar')
# => http://some.api.com

I have seen this pattern implemented in a few APIs (we can debate the design of said APIs another time). Is this possible with uri_template? If not, would there be any interest in me adding it?

If there is interest in me adding it, could we discuss what the pattern would look like for both formats?

Thanks!

@hannesg
Copy link
Owner

hannesg commented Aug 22, 2013

Hi

The colon template in uri_template is currently ultra-simple, so this isn't currently possible. I think it would be great if that was possible. My initial idea for the colon style templates was to implement rails/sinatra-style patterns so that people can simply reuse their routing patterns. So I'd prefer the rails syntax for conditionals: http://some.api.com(/:optional(/:optional2)). Maybe subclassing the colon template class for the different flavours (rails, sinatra, your own ... ) would be an option, too.

Anyway, you have push access now.

Cheers'
Hannes

@andrewpthorp
Copy link
Collaborator Author

Thanks! I'll work on this asap.

@hannesg
Copy link
Owner

hannesg commented Aug 23, 2013

Cool!

@hannesg
Copy link
Owner

hannesg commented Sep 2, 2013

Hi @andrewpthorp

Any progress so far? Can I help?

@andrewpthorp
Copy link
Collaborator Author

Hey @hannesg - I was actually on a family vacation all week last week. Going to start on this in the next few days.

I'll let you know where I can help, perhaps we can pair on it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants