Skip to content

Opinionated package for building HTTP RESTFul API

License

Notifications You must be signed in to change notification settings

phogolabs/restify

Repository files navigation

restify

Documentation License Build Status Coverage Go Report Card

An Opinionated package for building HTTP RESTFul API

Installation

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

Getting Started

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
	}
}

Contributing

We are open for any contributions. Just fork the project.

About

Opinionated package for building HTTP RESTFul API

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages