Trot v0.7.0 Trot.Versioning View Source

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.

Link to this section Summary

Functions

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

Same as build_version_match/1 but with an existing dictionary of match options passed in

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

Link to this section Functions

Link to this function build_version_match(version) View Source

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

Examples:

iex> Trot.Versioning.build_version_match(nil)
%{}
iex> Trot.Versioning.build_version_match(:any)
%{}
iex> Trot.Versioning.build_version_match("v1")
%{version: "v1"}
Link to this function build_version_match(matcher, version) View Source

Same as build_version_match/1 but with an existing dictionary of match options passed in.

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