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

Regexp for routing params - requirements feature #145

Closed
wants to merge 2 commits into from

Conversation

rodzyn
Copy link
Contributor

@rodzyn rodzyn commented Feb 19, 2012

I was investigating #127 bug and here is my proposal for a solution.
In this branch you can provide 'requirements' into your routing options like:

get '/:person_email', :requirements => { :person_email => /.*/ } do
end

Or even:

get '/:person_email/smth/:test', 
  :requirements => { :person_email => /rodzyn(.*)\.pl/, :test => /[A-z]/ } do
end

However I had to change a bit formatter middleware - now, when he can't match any formatter he always returns default one.
What do you think?

@dblock
Copy link
Member

dblock commented Feb 20, 2012

I have mixed feelings about this. In my experience features built for parameter validation have weird side effects. The first problem is that it's easy to step out of normal URL encoding. So if I were building an API where emails are used in the URL, I would slug them. For example, rodzyn-at-gmail-com would be used instead of rodzyn@gmail.com.

@rodzyn
Copy link
Contributor Author

rodzyn commented Feb 20, 2012

I would use something similar, either. I just thought that #127 is still considered as an error, so I have tried to provide any solution for this particular (but a little strange) form of request.
Here is also a request for param regexp (https://groups.google.com/group/ruby-grape/browse_thread/thread/4e4cf6e1cbb06984)

@dblock
Copy link
Member

dblock commented Feb 23, 2012

I'm going to close this, please comment/reopen if you feel strongly about this implementation needing to make it into Grape.

@dblock dblock closed this Feb 23, 2012
@gaiottino
Copy link
Contributor

I've simplified @rodzyn's work a bit and created my own pull request here: #159. Issue discussion is here: #158. Didn't find a way to add the pull request to the initial issue.

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

Successfully merging this pull request may close these issues.

3 participants