httpr/README.md

36 lines
762 B
Markdown

# httpr
It is an implementation of yet another HTTP router.
The reason why this router was made is to be able to have pretty paths with
parameters and regular endpoints at the same level. Like this:
GET /:a/:b
GET /assets/*filepath
In routers like httprouter this is not allowed.
This router is used like many others., example:
r := httpr.New()
r.Handler(http.MethodGet, "/", func(w http.ResponseWriter, r *http.Request) {
...
})
r.ServeStatic("/assets/*filepath", http.FS(os.Dir(".")))
r.NotFoundHandler = func(w http.ResponseWriter, r *http.Request) {
...
}
s := r.Sub("/api/v1")
s.Handler(http.MethodGet, "/", func(w http.ResponseWriter, r *http.Request) {
...
})
if err := http.ListenAndServe(":8000", r); err != nil {
...
}