beatlabs / patron

Microservice framework following best cloud practices with a focus on productivity.
Apache License 2.0
123 stars 67 forks source link

Improve URL parameter handling for RawRoutes #224

Closed tpaschalis closed 4 years ago

tpaschalis commented 4 years ago

Is your feature request related to a problem? Please describe

I think that there isn't a straightforward way for RawRoutes to capture dynamic URL parameters, such as /user/:id/profile. The URL is matched correctly via our router, as both normal and raw routes are handled similarly.

The easiest way to do this now involves adding an explicit dependency on julienschmidt/httprouter, and using params := httprouter.ParamsFromContext(r.Context()).

This kind of defeats the purpose of 'hiding' our router, and making it pluggable.

Is this a bug? Please provide steps to reproduce, a failing test etc.

Not a bug, more than a feature request.

Describe the solution

An extracted, wrapper function that works like extractParams could be added, allowing people that use RawRoutes to access the dynamic URL parameters without resorting to regular expressions or strings.Split(r.URL.Path, "/")

Additional context

I could take a look over the weekend and see if we can come up with a non-intrusive solution.

mantzas commented 4 years ago

Hey, nice catch... The problem here is that every router handles the dynamic URL parts a little bit differently. Would exporting the extract function work? Since we are using the specific http router we need to use the specific extractor... Just a thought.

tpaschalis commented 4 years ago

We were thinking of a new method that would reuse the current extractor; if/when we change our router, we'd have to change that too, and the user wouldn't notice.

I'll come up with something over the weekend and we can discuss on that.