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

Already on GitHub? Sign in to your account

Updating "Describing and Inspecting an API" to reflect actual behavior #195

Merged
merged 3 commits into from Jul 3, 2012

Conversation

Projects
None yet
2 participants
Contributor

ppadron commented Jul 3, 2012

In the current example, parameters are listed with an array instead of hash:

get "split/:string", { :params => [ "token" ], :optional_params => [ "limit" ] } do

However, it throws the following error: TypeError: can't convert Array into Hash

I have updated the example to use hashes and added a sample helper that performs parameter checking based on the provided information.

@dblock dblock and 1 other commented on an outdated diff Jul 3, 2012

README.markdown
@@ -670,6 +670,33 @@ class MyAPI < Grape::API
end
```
+You can use this information to create a helper that will check if the request has
+all required parameters:
+
+``` ruby
+class MyAPI < Grape::API
+
+ helpers do
+ def validate_request!
+ # skip validation if no parameter is declared
+ if route.route_params.nil?; return end
@dblock

dblock Jul 3, 2012

Owner

Maybe unwrap this line?

return unless route.route_params
@ppadron

ppadron Jul 3, 2012

Contributor

hah, that's much better.

Owner

dblock commented Jul 3, 2012

Merging, thank you for the update.

dblock added a commit that referenced this pull request Jul 3, 2012

Merge pull request #195 from ppadron/master
Updating "Describing and Inspecting an API" to reflect actual behavior

@dblock dblock merged commit 575e6fc into ruby-grape:master Jul 3, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment