modulepackage
0.0.0-20221219135034-356dc927fc4a
Repository: https://github.com/phogolabs/restify.git
Documentation: pkg.go.dev
# README
restify
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.
# Functions
DecodeForm decodes a object from Form reader.
DecodeJSON decodes a object from JSON reader.
DecodeXML decodes a object from XML reader.
EncodeForm marshals 'obj' to URL encoded data, and setting the Content-Type as application/x-www-form-urlencoded.
EncodeJSON marshals 'obj' to JSON, automatically escaping HTML and setting the Content-Type as application/json.
EncodeXML marshals 'obj' to JSON, setting the Content-Type as application/xml.
GetLogger returns the associated request logger.
NewDecoder creates a new decoder.
NewEncoder creates a new encoder.
NewReactor creates a new reactor.
NewValidator creates a new validator.
ParseContent parse the content type.
# Constants
ContentTypes handled by this package.
ContentTypes handled by this package.
ContentTypes handled by this package.
ContentTypes handled by this package.
ContentTypes handled by this package.
ContentTypes handled by this package.
ContentTypes handled by this package.
# Type aliases
ContentType is an enumeration of common HTTP content types.