HX is a lightweight, flexible HTTP framework for Go that simplifies request handling and data extraction. It provides a clean, type-safe way to handle HTTP requests with minimal boilerplate.
- 🚀 Lightweight and fast
- 💪 Type-safe request data extraction
- 🔄 Automatic request binding
- 🛠 Extensible design
require go version 1.24+
go get github.com/eatmoreapple/hx
Here's a simple example that demonstrates the core features of HX:
package main
import (
"context"
"net/http"
"github.com/eatmoreapple/hx"
. "github.com/eatmoreapple/hx/httpx"
)
type Router string
func (r Router) ValueName() string {
return "id"
}
type Ua string
func (u Ua) ValueName() string {
return "user-agent"
}
type User struct {
Name string `json:"name" form:"name"` // extract from request query
Id FromPath[Router] `json:"id"` // extract from request path
Ua FromHeader[Ua] `json:"ua"` // extract from request header
}
func app(ctx context.Context, extractor User) (any, error) {
return extractor, nil
}
func main() {
router := hx.New()
router.GET("/{id}", hx.G(app).JSON())
http.ListenAndServe(":9999", router)
}
Open your browser and navigate to http://localhost:9999/1?name=eatmoreapple
You should see a response like:
{
"name": "eatmoreapple",
"id": "1",
"ua": "Mozilla/5.0 ..."
}
HX is released under the Apache License 2.0.