I'm pretty new to Ruby, I know a little bit of Sinatra but what I actually need for my app is Grape for rest api.
Working with a method with parameters at all works like a charm, but when I'm trying to add parameters I get 404 not found exception.
Where am I going wrong here? Thanks
resource :devs do
desc "Get all devs"
get do
authenticate!
Dev.all
end
desc "Get dev by email"
params do
requires :email, type: String, desc: "Dev's email"
end
route_param :email do
get do
authenticate!
@devs = Dev.all(:email == params[:email])
#!error('email not found', 204) unless @devs.length > 0
end
end
desc "Get dev by API key"
get :key do
authenticate!
@dev = Dev.first(:api_key == params[:key])
!error('email not found', 204) unless @devs.length > 0
end
end
This is the call I make in PostMan (I also added the header for Apikey there)
localhost:9292/devs/email/orelzion@gmail.com
But it always give me the same result 404
If I'm on the other hand, trying to access the method like this
localhost:9292/devs?email=orel...@gmail.com
Then it will go starightly into the main function, and not into the function with the parameters
Does it work if you specify 'foobar' instead of an actual email?
The argument should be URL encoded or you need to change the route's requirements (check README). The default parser is probably confused because it thinks .com is some kind of formatting extension.
--
You received this message because you are subscribed to the Google Groups "Grape Framework Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-grape+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
localhost:9292/devs?email=orelzi...@gmail.com
Then it will go starightly into the main function, and not into the function with the parameters
get ':email', :requirements => { :email => /.*/ } do
... params[:email]
end
localhost:9292/devs?email=orelzi...@gmail.com
desc "Get dev by email"
params do
requires :email, type: String, desc: "Dev's email"
end
get ':email', requirements: { email: /.*/ } do
authenticate!
Dev.all(:email => params[:email])
endEnter code here...