httprouter icon indicating copy to clipboard operation
httprouter copied to clipboard

Add support for fasthttp

Open valyala opened this issue 9 years ago • 8 comments

fasthttp is a fast http server with zero memory allocations like httprouter. It would be great if support for fasthttp will be added to httprouter. This will give us fast http server+router with zero memory allocations.

valyala avatar Nov 29 '15 22:11 valyala

I am wondering, since httprouter would probably want to keep their API stable, what would this look like?

  • One could probably convert fasthtp.RequestCtx to a http.Request object - (nullifying the performance gain?)
  • One could probably convert fasthttp.RequestCtx to implement http.Responsewriter - but again, as it's not an http.ResponseWriter already, I would feel like this doesn't leave us with much performance gain either.
  • One could combine the two projects, resulting in a different API.

With "stable API", I mean: I expect @julienschmidt to want to keep the syntax:

func Hello(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {}

Do you have any thoughts / ideas about this yourself, @valyala ?

EtienneBruines avatar Dec 02 '15 14:12 EtienneBruines

The project is very interesting. I talked about something like that with @manucorporat a while ago. However support can not be simply added to httprouter as its API is designed for net/http. I think the best option would be to maintain a fork for fasthttp instead. I'd be happy to do that as soon as I fixed some stuff here in the main repo.

julienschmidt avatar Dec 02 '15 16:12 julienschmidt

I'd be happy to do that as soon as I fixed some stuff here in the main repo.

This would be great!

valyala avatar Dec 08 '15 14:12 valyala

What are we looking at for a timeline for this? Would you like any help with the fork? Thanks!

mathvav avatar Dec 09 '15 05:12 mathvav

Hi all.

I had forked [httprouter] and make it work for [fasthttp]. But there are too many conflicts with go's net/http package. It is hard to merge into the main repo, so I rename it as an individual package fasthttprouter.

All docs and tests are available and the package has been used in our online productions. Just enjoy it.

buaazp avatar Dec 13 '15 11:12 buaazp

Thanks @buaazp for your work.

Taik avatar Dec 15 '15 16:12 Taik

@buaazp looks great; planning on digging into your library to build a framework with middleware and such Sunday or Monday.

Can I ask how you are going to maintain fasthttprouter as httprouter evolves? Why don't you have issues enabled for it (are you not looking to maintain this long-term?)?

mathvav avatar Dec 18 '15 21:12 mathvav

Hi @Annonomus-Penguin , forked repos disable issues by default, now I have opened it. I will rebase the httprouter's commits into fasthttprouter over a period of time. Before I can make a PR for httprouter. I wish httprouter can support fasthttp finally. But the interfaces are different and it's a little hard to do that. And, of cause, I will maintain fasthttprouter as a long-term project because it's used in my productions. If there are bugs, file it to me.

buaazp avatar Dec 19 '15 14:12 buaazp