Skip to content

VoxA Go web framework for humans

Koa style middleware and typed route handlers, on top of net/http.

A quick look ​

Vox is a small web framework built on two ideas. Requests flow through a chain of middleware, as in Koa, and route handlers declare the types of their request and response bodies in their signature.

go
package 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()

	// A 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()
		res.Header.Set("X-Response-Time", fmt.Sprintf("%s", time.Since(start)))
	})

	// A route with a path parameter and a plain text response.
	app.Get("/hello/{name}", func(ctx *vox.Context, req *vox.Request[vox.NoBody], res *vox.Response[string]) {
		res.Body = "Hello, " + req.Params["name"] + "!"
	})

	// A route that decodes a JSON body and responds with JSON.
	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")
}

Vox requires Go 1.27 or later.

Where to go next ​

If you want toRead
Build and run a first applicationGetting Started
Understand how requests are matchedRouting
Understand typed handlersRoute Handlers
Write your own middlewareMiddleware
Serve files or expose profiling endpointsBundled Middleware
Copy a working snippet for a common taskRecipes
Look up a type or methodAPI reference

Released under the MIT License.