nokia / restful

A powerful RESTful framework for Go.
BSD 3-Clause "New" or "Revised" License
17 stars 14 forks source link
golang golang-library rest restful

RESTful

Quick introduction

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.

Reference.

Lambda server

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: reqData.Num}
    return &respData, nil
}

func main() {
    restful.HandleFunc("/user/v1", create).Methods(http.MethodPost)
    restful.Start()
}

RESTful client

You send and receive data structures.

location, err := restful.Post(ctx, "https://example.com", &reqData, &respData)

Details

Trace context and error are the glue between Lambda and Client. That is why they form a module together.

Principles