httpin
httpin copied to clipboard
integrate with more web frameworks
any suggestions?
seamless integration with go-restful would be awesome!
@bokunodev thanks for the suggestion, i'll look into it :)
the implementation is really straight forward, i think. since go-restful expose Request
and ResponseWriter
from net/http
.
integration with go-restful could be implemented as an adapter.
httpin-go-restful-adapter i can work on it. but i want to hear your opinion. do you have better solution?
Thanks again @bokunodev, I'm so sorry that I'm busy these days and late to respond, but I think httpin-go-restful-adapter is a good idea and it's also an intuitive solution IMO. I'm very glad that you'd like to contribute to it, most welcome :)
Hi @bokunodev, I know you are working on something about integrating httpin with go-restful. After some research, I find it will be much more helpful to make go-restful be able to easily adopt existing http middleware handlers. I have made a pull request to go-restful. I'm not sure if it can be merged to their source. But I'm glad to keep you posted about my work.
hi, sorry for not submitting the pr as promised. i got a little bit busy.
my original solution was basically to call engine.Decode
inside route.FilterFunction
and make use of request attribute instead of context.
Hi @bokunodev, since the PR mentioned above has been merged to go-restful and here I'd like to recommend using httpin by converting http.NewInput(...)
to a FilterFunction
in go-restful:
Here's a demo to showcase this in an intuitive way:
type ListUsersInput struct { ... }
ws := new(WebService)
ws.Route(ws.GET("/users").Filter(
restful.HttpMiddlewareHandlerToFilter(httpin.NewInput(ListUsersInput{})),
).To(handleListUsers))
func handleListUsers(request *restful.Request, response *restful.Response) {
input := request.Request.Context().Value(httpin.Input).(*ListUsersInput)
// ...
}
I hope this would help you :)