https://github.com/hemantjadon/respond
Low friction, simple API for HTTP responses in go
https://github.com/hemantjadon/respond
go golang http
Last synced: 3 months ago
JSON representation
Low friction, simple API for HTTP responses in go
- Host: GitHub
- URL: https://github.com/hemantjadon/respond
- Owner: hemantjadon
- License: mit
- Created: 2020-01-26T10:45:33.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-06-03T09:53:41.000Z (almost 6 years ago)
- Last Synced: 2024-06-20T08:02:18.117Z (almost 2 years ago)
- Topics: go, golang, http
- Language: Go
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# respond

Package responds provides low touch, minimal API for sending HTTP API responses
in go.
For simple string responses can be used simply as:
```go
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:
```go
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.