-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
How grape recognizes a path? #1072
Comments
Grape uses Rack::Mount, which is now yanked from Github. I actually would like to use this opportunity to figure out what the recommended replacement is and maybe find out a bit about the history of why it was yanked? |
/cc: @josh |
anyone? |
@vasilakisfil The "how" part is rack-mount, and you can look at the source via |
I hate it when such vital gems don't have documentation......... and why on earth they removed it? it's free to have it somewhere on github... After 2 hours looking on the rack-mount code, I couldn't figure out what object accepts recognize method of RouteSet class... Any help is really appreciated.. I have a route string ('/api/v1/foobars') and some request options (like {method: :get} etc) and I need somehow to get the path from grape api..... |
seems it's just an instance of Rack::Request(or Grape) @request_class = options.delete(:request_class) || Rack::Request
...
req = @request_class.new(env)
recognize(req) do |route, matches, params|
...
end so you can prepare mocked_env = Rack::MockRequest.env_for('/api/v1/foobars', {:method => 'GET', :params => { foo: 'bar' }})
request = Rack::Request.new(mocked_env)
routes = route_set.recognize(request) or smth similar
really interesting.. |
Thanks! |
Nice work @dm1try. Should Grape provide a helper? Or maybe an extension or a separate gem? |
@dblock I honestly don't have a good use-case of using this feature in my flow(debugging? seems we need to make |
As far as I remember, rack-mount used to be router used by Rails up to 3.1 [1], then the Journey was developed as a replacement and later subsumed into Rails, where it still lives [2]. [1] rails/rails@5f0b37c |
Just FTR, there is attempt to package Grape for Fedora [1], since it is in GitLab's dependency chain and it'd be great if the rack-mount dependency could be avoided. As much as I hate to say that, it might be even reasonable to vendor the rack-mount, if the functionality fit Grape's needs. |
I would take a PR that replaces rack-mount with journey, vendors it, or whatever is needed. |
We (someone :) should try https://github.com/hanami/router. |
We replaced the router in #1276. Maybe we can do something about this now? /cc: @namusyaka |
Yeah, I guess we can do provide the helper, I'm going to try to implement it. |
Closed via #1339. |
In rails there is Rails.application.routes.recognize_path: http://www.rubydoc.info/docs/rails/ActionDispatch/Routing/RouteSet#recognize_path-instance_method
Is there anything similar for Grape?
The text was updated successfully, but these errors were encountered: