Quickly write RESTful APIs in go with automatic openapi schema generation.
Inspired by the simplicity of FastAPI.
go get github.com/fcjr/shiftapi
package main
import (
"context"
"errors"
"log"
"net/http"
"github.com/fcjr/shiftapi"
)
type Person struct {
Name string `json:"name"`
}
type Greeting struct {
Hello string `json:"hello"`
}
func greet(ctx context.Context, headers http.Header, person *Person) (*Greeting, error) {
return &Greeting{
Hello: person.Name,
}, nil
}
func main() {
ctx := context.Background()
server := shiftapi.New(shiftapi.WithInfo(shiftapi.Info{
Title: "Geeter Demo API",
Description: "It greets you by name.",
}))
handleGreet := shiftapi.Post("/greet", greet)
_ = server.Register(handleGreet) // You should handle errors in production code.
log.Fatal(server.ListenAndServe(ctx, ":8080"))
// redoc will be served at http://localhost:8080/docs
}