You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Recognize_path should account for HTTP method #2415
Indeed. I am actually kinda surprised it doesn't. Start by writing a spec that (fails to) differentiate(s) multiple methods on the same API. What do we return today? The first matching route? In which case I think we should consider making this recognize_path(path, verb = 'GET') vs. adding an options hash. What other options would make sense?
I was taking a look to this issue. As @ideaoforder described, when using the recognize_path method, we are not able to specify the method. So in case you have more than one method for the same path, you will get always the one defined in the last position.
Check with this spec that when obtaining the routes for the /books path, we only get one of them.
We need to define which behaviour we want for the recognize_path method (in case we want to change it):
Option a
Add an optional parameter verb/method, to the recognize_path method.
If not received, it will continue behaving as it is, just returning the last endpoint defined.
If received, return the endpoint that matches the path and the provided verb.
Internally, when verb/method parameter is provided, it will continue delegating into the greedy_match?(input) method for finding a match with the provided input. On the other hand, if verb/method parameter is provided, it will delegate into the match?(input, method) method, that takes into account the method and will select the correct one depending on the provided method.
In this option, the routes will always return ONLY 0 or 1 routes inside the routes array.
Option b
Add an optional parameter verb/method, to the recognize_path method.
If not received, return all the possible routes and return them inside the routes array.
If received, return the endpoint that matches the path and the provided verb.
In this option, the routes will always return 0, 1 or N routes inside the routes array.
This is the option that is added to jcagarcia@919f5f3 as a failed spec.
For this Option b is pending to check how to include all the routes inside the array could affect the detection of the routes in Grape.
Option b) is a breaking change whereas option a) is not but doesn't behave the way we want.
I think a cleaner option would be c) add a new method called, for example, routes(path, verb = nil) that behaves like b), and deprecate recognize_path. WDYT?
Reacted by Juan Carlos García del Canto and Mark Dickson
Activity
dblock commentedon Feb 24, 2024
Indeed. I am actually kinda surprised it doesn't. Start by writing a spec that (fails to) differentiate(s) multiple methods on the same API. What do we return today? The first matching route? In which case I think we should consider making this
recognize_path(path, verb = 'GET')vs. adding anoptionshash. What other options would make sense?fix(ruby-grape#2415): Failed spec when recognizing two paths with the…
jcagarcia commentedon Oct 4, 2024
Hey 👋
I was taking a look to this issue. As @ideaoforder described, when using the
recognize_pathmethod, we are not able to specify the method. So in case you have more than one method for the same path, you will get always the one defined in the last position.Check with this spec that when obtaining the routes for the
/bookspath, we only get one of them.jcagarcia@919f5f3
We need to define which behaviour we want for the
recognize_pathmethod (in case we want to change it):Option a
verb/method, to therecognize_pathmethod.verb.Internally, when
verb/methodparameter is provided, it will continue delegating into thegreedy_match?(input)method for finding a match with the provided input. On the other hand, ifverb/methodparameter is provided, it will delegate into thematch?(input, method)method, that takes into account the method and will select the correct one depending on the provided method.In this option, the
routeswill always return ONLY 0 or 1 routes inside theroutesarray.Option b
verb/method, to therecognize_pathmethod.routesarray.verb.In this option, the
routeswill always return 0, 1 or N routes inside theroutesarray.This is the option that is added to jcagarcia@919f5f3 as a failed spec.
For this Option b is pending to check how to include all the routes inside the array could affect the detection of the routes in Grape.
jcagarcia commentedon Oct 8, 2024
What do you think @dblock ?
dblock commentedon Oct 8, 2024
Option b) is a breaking change whereas option a) is not but doesn't behave the way we want.
I think a cleaner option would be c) add a new method called, for example,
routes(path, verb = nil)that behaves like b), and deprecaterecognize_path. WDYT?