Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integrate with go-restful #23

Closed
ggicci opened this issue Mar 3, 2022 · 7 comments
Closed

integrate with go-restful #23

ggicci opened this issue Mar 3, 2022 · 7 comments
Labels
enhancement New feature or request

Comments

@ggicci
Copy link
Owner

ggicci commented Mar 3, 2022

any suggestions?

@ggicci ggicci added the enhancement New feature or request label Mar 3, 2022
@ggicci ggicci changed the title integrate with more top web frameworks integrate with more web frameworks Mar 4, 2022
@bokunodev
Copy link

bokunodev commented Jun 25, 2022

seamless integration with go-restful would be awesome!

@ggicci
Copy link
Owner Author

ggicci commented Jun 27, 2022

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

@bokunodev
Copy link

bokunodev commented Jul 14, 2022

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?

@ggicci
Copy link
Owner Author

ggicci commented Jul 14, 2022

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
Copy link
Owner Author

ggicci commented Jul 20, 2022

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.

@bokunodev
Copy link

bokunodev commented Jul 20, 2022

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.

@ggicci
Copy link
Owner Author

ggicci commented Jul 22, 2022

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 ggicci changed the title integrate with more web frameworks integrate with go-restful Aug 13, 2022
@ggicci ggicci closed this as completed Aug 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants