Skip to content
/ responder Public
forked from qor/responder

Responder: Respond differently according to request's accepted mime type

License

Notifications You must be signed in to change notification settings

qorx/responder

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Responder

Responder provides a means to respond differently according to a request's accepted mime type.

GoDoc Build Status

Usage

Register mime type

import "github.com/qor/responder"

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

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

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 cannot find a corresponding mime type.

License

Released under the MIT License.

About

Responder: Respond differently according to request's accepted mime type

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%