Hi Team,
I need to implement the API versioning. we thought of using accept media type to differentiate api versions.
I am using mux gorilla router. how can i send dynamically incoming request to appropriate handler based on media type version?
Alternatively you could use multiple routers (one for reaching API version) and write a single http handler that determines version and picks the correct router to use. Both sound like good options depending on your use case.
You do not NEED to create 2 routers. Check out the docs and the Headers() method that @lutzhorn mentioned and you should see how it all works. I simply meant that it might be easier to design that way if you were dealing with many versions.
Why do you do that? A HTTP client must not specify the Accept header more than once for a HTTP request. It can specifiy multiple accepted content types:
// Multiple types, weighted with the quality value syntax:
Accept: text/html, application/xhtml+xml, application/xml;q=0.9, */*;q=0.8
Headers do match the header pair value for each incoming request and accept/reject accordingly but there is no way to pass the request to appropriate handler func.
I am thinking to check the version in the handler method and pass the request to different version handler from there. though it is very ugly way.