httpin icon indicating copy to clipboard operation
httpin copied to clipboard

integrate with more web frameworks

Open ggicci opened this issue 2 years ago • 7 comments

any suggestions?

ggicci avatar Mar 03 '22 11:03 ggicci

seamless integration with go-restful would be awesome!

bokunodev avatar Jun 25 '22 19:06 bokunodev

@bokunodev thanks for the suggestion, i'll look into it :)

ggicci avatar Jun 27 '22 08:06 ggicci

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?

bokunodev avatar Jul 14 '22 03:07 bokunodev

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 :)

ggicci avatar Jul 14 '22 03:07 ggicci

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.

ggicci avatar Jul 20 '22 11:07 ggicci

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.

bokunodev avatar Jul 20 '22 19:07 bokunodev

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 :)

ggicci avatar Jul 22 '22 06:07 ggicci