An Opinionated package for building HTTP RESTFul API
Make sure you have a working Go environment. Go version 1.13.x is supported.
See the install instructions for Go.
To install restify
, simply run:
$ go get github.com/phogolabs/restify
type CreateUserInput struct {
FirstName string `json:"first_name" header:"-" validate:"required"`
LastName string `json:"last_name" header:"-" validate:"required"`
CreatedBy string `json:"-" header:"X-Created-By" validate:"-"`
}
type CreateUserOutput struct {
UserID string `json:"user_id"`
}
func (output *CreateUserOutput) Status() int {
return http.StatusCreated
}
func create(w http.ResponseWriter, r *http.Request) {
reactor := restify.NewReactor(w, r)
var (
input = &CreateUserInput{}
output = &CreateUserOutput{}
)
if err := reactor.Bind(input); err != nil {
reactor.Render(err)
return
}
// TODO: implement your logic here
if err := reactor.Render(output); err != nil {
reactor.Render(err)
return
}
}
We are open for any contributions. Just fork the project.