An Elixir Plug for routing requests to other Plugs based on the request's Media Type. See this GitHub document for more information on Media Types.
The typical use case is as part of an API which has multiple versions.
Consumers of the API can specify which version of the API they wish to use via
the Accept
header.
Update your mix.exs
file and run mix deps.get
:
def deps do
[{:plug_media_type_router, "~> 0.0.1"}]
end
Add the Plug to wherever you would normally place a Plug.Router
. For
Phoenix applications, this is the last line in endpoint.ex
. Options you
need to provide to the Plug are:
- Default version to route to
- Map of versions and their routes
- Your vendor producer's name (e.g. "application/vnd.my_app.v1+json")
plug PlugMediaTypeRouter,
default_version: "v2",
name: "my_app",
routers: %{
"v1" => MyApp.V1.Router,
"v2" => MyApp.V2.Router,
"v3" => MyApp.V3.Router
}
See CONTRIBUTING.md.
See LICENSE.