Skip to content

Commit

Permalink
Update responder README
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhu committed Oct 31, 2017
1 parent 2d88208 commit b6def47
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,36 @@ Responder provides a means to respond differently according to a request's accep

[![GoDoc](https://godoc.org/github.com/qor/responder?status.svg)](https://godoc.org/github.com/qor/responder)

## Documentation
## Usage

<https://doc.getqor.com/helpers/responder.html>
### Register mime type

```go
import "github.com/qor/responder"

responder.Register("text/html", "html")
responder.Register("application/json", "json")
responder.Register("application/xml", "xml")
```

[Responder](https://github.com/qor/responder) has the above 3 mime types registered by default. You can register more types with the `Register` function, which accepts 2 parameters:

1. The mime type, like `text/html`
2. The format of the mime type, like `html`

### Respond to registered mime types

```go
func handler(writer http.ResponseWriter, request *http.Request) {
responder.With("html", func() {
writer.Write([]byte("this is a html request"))
}).With([]string{"json", "xml"}, func() {
writer.Write([]byte("this is a json or xml request"))
}).Respond(request)
})
```

The first `html` in the example will be the default response type if [Responder](https://github.com/qor/responder) cannot find a corresponding mime type.

## License

Expand Down

0 comments on commit b6def47

Please sign in to comment.