go-martini / martini

Classy web framework for Go
martini.codegangsta.io
MIT License
11.63k stars 1.1k forks source link

Mapping same URL to different handler base on MIMETypes #381

Closed lysu closed 7 years ago

lysu commented 9 years ago

Hi, I want to use strict.Accept to build versioned api base on HTTP Accept Header..

like heroku one https://github.com/interagent/http-api-design#require-versioning-in-the-accepts-header

but after trying found it doesn't work

    m.Post("/zoo", strict.Accept("application/vnd.company+json; version=1"), func(n strict.Negotiator, r render.Render) {
        r.JSON(200, struct {
            S bool
        }{true})
    })
    m.Post("/zoo", strict.Accept("application/vnd.company+json; version=2"), func(n strict.Negotiator, r render.Render) {
        r.JSON(200, struct {
            R bool
        }{true})
    })

version=1 accepted...but version=2 406 Not Acceptable...

I think it's a common requirement to mapping handler base on MIMETypes to make them both worked.