Support for httpcontext handlers?
jaytaylor opened this issue · 2 comments
Hi,
I really like the concept behind hitch and httpcontext, however I am finding the repetitive boilerplate quite tiresome
e.g.:
h.Post("/v1/register", http.HandlerFunc(myService.registerEndpoint))
compared to what I had with httprouter alone:
router.POST("/v1/register", myService.registerEndpoint)
Additionally, with httprouter alone I can access request parameters easily like so:
func (myService *MyService) home(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
id := ps.ByName("id")
...
}
Whereas with Hitch painful repetitive boilerplate bits are necessary:
id := hitch.Params(r).ByName("id")
Compatibility with httprouter.Params in the function signature would be fantastic.
Like I said, I really like the core concept here and am enthusiastic at the prospect of being able to use the hitch library in my projects, but these pain points would need to be cleaned up for it to be a viable path. Do you have any plans to clean up these interfaces?
Alternatively, if I were to do the work to smooth out the aforementioned interfaces would you accept the PR's? Or are you adamant on not changing things at this point?
Best,
Jay
The entire point of hitch is interop with vanilla http.Handlers
, so no plans to incorporate httprouter’s method signature. This would add API complexity, either doubling the method count or using an interface{}
argument.
I suppose you can add ps := hitch.Params(r)
at the top of your handler to DRY it up.
After looking through the code more I am 100% in agreement with you. Thanks for the followup.