Trot.Versioning

Module for handling API versioning within requests.

To automatically retrieve the requested API version, add Trot.Versioning to the list of plugs either manually or by using it. Endpoints can also be set to only match a specific version using the version option. The special value :any will match every version, which is also the default behavior.

Example

defmodele SickAPI do
  use Trot.Versioning
  use Trot.Router

  get "/sweet_endpoint", version: "beta" do
    {:bad_request, "Naw man, that's not ready yet."}
  end

  get "/sweet_endpoint" do
    "Sweet! #{conn.assigns[:version]} is up!"
  end
end

$ curl localhost:4000/v1/sweet_endpoint
Sweet! v1 is up!

$ curl localhost:4000/beta/sweet_endpoint
Naw man, that's not ready yet.
Source

Summary

build_version_match(version)

Returns a quoted match against the passed in version for use in routing requests

build_version_match(matcher, version)
version(conn, opts)

Plug for pulling the API version out of the request path and assigning it to the connection

Functions

build_version_match(version)

Returns a quoted match against the passed in version for use in routing requests.

Source
build_version_match(matcher, version)
Source
version(conn, opts)

Plug for pulling the API version out of the request path and assigning it to the connection.

Source