Typed HTTP APIs in Go
ezz sits on top of
net/http. Your handler takes a typed request and returns a typed response; the framework binds the request from struct tags, validates it, checks the caller's roles, and generates the OpenAPI spec from the same types.One type, four jobs
GetUserRequest describes the path parameter and the query string, so ezz can bind it, validate it, document it in /openapi.json, and hand your function a filled-in struct. There is no code generation step and no reflection on the request path.main.go
type GetUserRequest struct {
ID string `path:"id" validate:"required" description:"User ID"`
Fields string `query:"fields" default:"basic"`
}
app := ezz.New().Auth(auth.NewJWTAuthProvider(jwt))
app.GET("/users/{id}", ezz.H(func(ctx *ezz.Context, req GetUserRequest) (*User, error) {
user, ok := store[req.ID]
if !ok {
return nil, ezz.NotFound("user not found")
}
return user, nil
})).Tags("Users")
What you get
Every part of the framework works with plain net/http types, so you can drop down a level whenever you need to.
Ready to build something?
Install the module, copy the quick start, and you have a documented, authenticated JSON API in about thirty lines.