aserafin / grape_logging

Request logging for Grape!
MIT License
147 stars 76 forks source link

url params missing in params hash #27

Closed scauglog closed 3 years ago

scauglog commented 8 years ago

when there is url parameters like

post "(:some_url)/test" do
 #some code here
end

there is no key "some_url" in the params hash.

scauglog commented 8 years ago

I can get it if i use request.env["api.endpoint"].params.to_h or env["api.endpoint"].params.to_h instead of request.params I don't know if there is any edge case, so i have created a new "loggers" named url_params. Tell me if you prefer modify request_logger.rb instead.

selcham commented 8 years ago

Hi, Same here, I tried your changes which seem to work fine.

aserafin commented 8 years ago

@scauglog do you declare you params also in params block like below or only in the url string?

params do
  requires :id, type: Integer
end 
get 'sth/:id' do 
end
scauglog commented 8 years ago

yes, I also declare my params in the params block

migmartri commented 6 years ago

Same problem here.

Previously I was using https://github.com/ridiculous/grape-middleware-logger which leverages the official Grape::Middleware::Globals to retrieve parameters.

This is how it reads the values pre-set by this other middleware

One solution would be to rely on Grape::Request.new (which has an enhanced params) as you can see here instead of Rack.request which is what this library currently uses.

Another solution is just to implement the parameters retrieval like in ridiculous/grape-middleware-logger although it will add the dependency on the global middleware.

What do you think?

aserafin commented 3 years ago

c