Skip to content

Low friction, simple API for HTTP responses in go

License

Notifications You must be signed in to change notification settings

hemantjadon/respond

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

respond

Go

Package responds provides low touch, minimal API for sending HTTP API responses in go.

For simple string responses can be used simply as:

func handler(w http.ResponseWriter, r *http.Request) {
     respond.With(w, http.StatusOK, []byte(`Hello World!`))
}

For more complex use cases where we want to send JSON across this respond provides handy utility function which can be used as follows:

type response struct {
    Message string `json: "message"`
}

func handler(w http.ResponseWriter, r *http.Request) {
    resp := response{Message: "Hello World!"}
    respond.WithJSON(w, http.StatusOK, response)
}

While sending JSON responses correct HTTP Content-Type: applocation/json; utf-8 is also set.

About

Low friction, simple API for HTTP responses in go

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages