gorest
Quickly build RESTful APIs in Go with auto-generated OpenAPI 3.1 documentation.
Quickstart
package main
import (
"context"
"log"
"net/http"
"github.com/kaptika/common/types"
"github.com/kaptika/gorest"
)
func sayHello(ctx context.Context, req *types.Empty) (*types.BasicResponse, error) {
return &types.BasicResponse{
Message: "Hello, World!",
}, nil
}
func main() {
server := gorest.New(gorest.Config{
Info: gorest.Info{
Title: "My API",
Description: "This is a sample server.",
Version: "1.0.0",
},
URLs: []string{"http://localhost:3000"},
})
gorest.Add(server, http.MethodGet, "/hello", sayHello)
log.Fatal(server.Start())
}
Then, run the program:
go run server.go
Browse to http://localhost:3000/docs and the OpenAPI documentation should be displayed.