I’m seeking for an idiomatic and lightweight HTTP router with acceptable performance.
LOC is a subjective figure to determine how lightweight a library is.
find chi -maxdepth 1 -name '*.go' \! -name '*_test.go' -print0 | xargs -0 cloc
HttpRouter, gorilla/mux
and chi
all have less than 2k lines of core code.
Besides LOC, the API surface is also a good reference on how idiomatic and lightweight a framework is.
Choosing an idiomatic router
Chi provides a library of reference middleware in addition to its core. It also provided convenience functions for each request method.
gorilla/mux
has a relatively large API surface. HTTP method constraint is more verbose than chi
, and some are too advanced, e.g. r.Headers()
and r.Queries()
.
HttpRouter has a very thin API surface. It’s good as a performant base for more advanced frameworks. I don’t like how functions are ALL CAPS, which makes it look less idiomatic (i.e. different from net/http
).
In conclusion, I prefer using chi
for now.