A Go web framework for humans, heavily inspired by Koa.
Requires Go 1.27 or later. Install with go get:
$ go get -u github.com/aisk/voxpackage main
import (
"fmt"
"time"
"github.com/aisk/vox"
)
type CreateUser struct {
Name string `json:"name"`
}
type User struct {
ID int `json:"id"`
Name string `json:"name"`
}
func main() {
app := vox.New()
// custom middleware that adds an X-Response-Time header
app.Use(func(ctx *vox.Context, req *vox.BaseRequest, res *vox.BaseResponse) {
start := time.Now()
ctx.Next()
duration := time.Now().Sub(start)
res.Header.Set("X-Response-Time", fmt.Sprintf("%s", duration))
})
// router param
app.Get("/hello/{name}", func(ctx *vox.Context, req *vox.Request[vox.NoBody], res *vox.Response[string]) {
res.Body = "Hello, " + req.Params["name"] + "!"
})
app.Post("/users", func(ctx *vox.Context, req *vox.Request[CreateUser], res *vox.Response[User]) {
res.Status = 201
res.Body = User{ID: 1, Name: req.Body.Name}
})
app.Run("localhost:3000")
}Route handlers declare their request and response body types in the function signature. Vox decodes request bodies as JSON; use Request[vox.NoBody] when no decoding is needed. Middleware receives BaseRequest and BaseResponse.
The full documentation lives at https://aisk.github.io/vox/.
- Getting Started
- Routing, Route Handlers and Middleware
- Request, Response and Error Handling
- Static Files and Pprof middleware
- Recipes
If you need help for using vox, or have other questions, welcome to our gitter chat room.
Vox is © 2016-2026 by aisk.
Vox is distributed by a MIT license.
