- Notifications
You must be signed in to change notification settings - Fork4
Lightweight net/http 1.22+ enhancement library that combines the best of chi & Echo Enabling you to effortlessly write handlers using net/http
License
aeilang/httpz
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
httpz v1.0.0 is release, its API is stable.
httpz is not a new framework but rather an enhancement library for net/http. When you use httpz, you’re essentially working with the net/http standard library. Its goal is to address the usability gap in net/http 1.22, which, despite its improved routing capabilities, remains less convenient compared to frameworks like Echo and chi.
Key Features:
- Built on net/http version 1.22+
- Global error handling
- Convenient grouping
- Middleware adopted from chi
- Data binding adopted from Echo
- Easy response shortcuts
httpz is fully compatible with net/http. You can choose to leverage the enhanced features of httpz or stick to using plain net/http directly.
To install httpz, Go 1.22 or higher is required.
go get github.com/aeilang/httpz
import ("net/http""github.com/aeilang/httpz""github.com/aeilang/httpz/middleware")funcmain() {// Create a new muxmux:=httpz.NewServeMux()// add logger middleware, it 's copy from chi/middlewaremux.Use(middleware.Logger)// register a GET /hello route// GET /hellomux.Get("/hello",func(w http.ResponseWriter,r*http.Request)error {returnhttpz.JSON(w,http.StatusOK,"hello httpz")// or// hw is a helper responsewriter to send response// hw := httpz.NewHelperRW(w)// return hw.String(http.StatusOK, "hello httpz")// or you can write it by yourself.// hw.Header().Set("Content-Type", "text/plain; charset=UTF-8")// hw.WriteHeader(http.StatusOK)// hw.Write([]byte("hello httpz"))// return nil})// just like net/http's ServerMuxhttp.ListenAndServe(":8080",mux)}
the middleware package is copied from chi/middleware.
The complete example can be found in the_example directory
Generated byGo web framework benchmark:
For detailed benchmark results, please refer tobenchmark.
test
example
middleware
other
About
Lightweight net/http 1.22+ enhancement library that combines the best of chi & Echo Enabling you to effortlessly write handlers using net/http