This Go package is a powerful extension of standard Go HTTP server and client libraries. It lets you handle HTTP+JSON without any extra code.
You receive and respond with data structures.
type reqData struct {
Num int `json:"num" validate:"lt=1000000"`
}
type respData struct {
Number int `json:"number"`
}
func create(ctx context.Context, req *reqData) (*respData, error) {
// You use data structures directly, without marshalling and unmarshalling.
resp := respData{Number: req.Num}
return &resp, nil
}
func main() {
restful.HandleFunc("/user/v1", create).Methods(http.MethodPost)
restful.Start()
}
You send and receive data structures.
location, err := restful.Post(ctx, "https://example.com", &reqData, &respData)
- Lambda server Focus on business logic. It is a modern variant of an HTTP server.
- RESTful server An underlying HTTP server of Lambda. An HTTP server with goodies. Besides helper functions for receiving and sending JSON data, it can do logging. Router is based on Gorilla/Mux, offering similar services.
- RESTful client Sending GET, POST (and receiving Location), PUT, PATCH or DELETE requests and receiving their responses. And numerous other helper functions.
- Tracing Information is propagated in context, received in Lambda, and used in client requests. That is all done without any extra coding on your side. Based on OpenTelemetry.
- Monitor is a convenient middleware solution to pre-process requests and post-process responses. Pre and post hooks can be used for whatever you want, such as adding Prometheus counters on the router level, without littering your business logic.
- Error is a Go error object containing an HTTP status code besides the traditional error.
Trace context and error are used both at Lambda Server and Client. These use similar middleware solution called Monitor. That is why, unlike many other Go HTTP router packages, they form a module together.
- Simple, intuitive, Go-ish.
- Similar to Go's built-in http package, with some advanced router inherited from Gorilla/Mux project.
- Powerful HTTP+JSON framework reducing development costs while improving quality.
- Has quite many goodies needed for developing complex applications.