httpr/README.md

30 lines
648 B
Markdown
Raw Normal View History

2023-05-26 01:50:54 +04:00
# httpr
2023-05-26 04:06:35 +04:00
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
2023-05-28 04:00:54 +04:00
parameters and regular endpoints at the same level. Like this:
2023-05-26 04:06:35 +04:00
2023-05-28 04:00:54 +04:00
GET /:a/:b
2023-05-26 04:06:35 +04:00
GET /assets/*filepath
2023-05-28 04:00:54 +04:00
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) {
...
}
if err := http.ListenAndServe(":8000", r); err != nil {
...
}