Skip to content

dnlgrv/plug_media_type_router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PlugMediaTypeRouter

Build Status

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.

Installation

Update your mix.exs file and run mix deps.get:

def deps do
  [{:plug_media_type_router, "~> 0.0.1"}]
end

Usage

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
  }

Contributing

See CONTRIBUTING.md.

License

See LICENSE.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages