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

accept format query parameter like rails to steer the response format #240

Merged
merged 1 commit into from
Sep 23, 2012

Conversation

neetiraj
Copy link

@neetiraj neetiraj commented Sep 6, 2012

This emulates the Rails behavior of identifying the expected response format from format query parameter if available. With this resolution Grape would be able to decipher that the expected response format is json from a URL like this - http://myblog.com/updates?format=json. This is from an issue that I reported in Grape google group - https://groups.google.com/forum/?fromgroups=#!topic/ruby-grape/uUFd-OcNwDM where the solution was accepted and suggested to do git pull for the same.

@dblock
Copy link
Member

dblock commented Sep 6, 2012

Doesn't params[:format] have what you want? Instead of parsing QUERY_STRING?

@dblock
Copy link
Member

dblock commented Sep 10, 2012

This also needs a README and a CHANGELOG update, please.

@neetiraj
Copy link
Author

I agree, params[:format] would be a much better solution than parsing QUERY_STRING. I am quite new to Rack stuff and params[:format] OR request.params[:format] OR env['rack.request.params'] is not giving me the query parameter.

@dblock
Copy link
Member

dblock commented Sep 18, 2012

I did 5 seconds of research. Looks like Rack::Request has a query_string, which looks at ENV, but probably should be the one used. Then I think we need to use a proper URL parser (URI? CGI?) here to extract this stuff.

When I have a moment, I'll play with it, but feel free to make additional pulls here.

@dblock dblock merged commit 9708c56 into ruby-grape:master Sep 23, 2012
@dblock
Copy link
Member

dblock commented Sep 23, 2012

I merged this change and rewrote the QUERY_STRING parser to use Rack::Utils (found via this SO q/a). Double-check my diff please.

Thanks for contributing!

@neetiraj
Copy link
Author

@dblock Rack::Utils query string parsing is quite an elegant solution. Thanks for guiding towards a cleaner approach.

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.

2 participants