GUIDES
GUIDESDOCS
GUIDES

Versioning

Here is a simple example. maru_version

1. add versioning to your config.exs

use Mix.Config

config :maru, MaruVersion.API,
  versioning: [
    using: :path
  ],
  http: [port: 4001]
use Mix.Config

config :maru, MaruVersion.API,
  versioning: [
    using: :param,
    parameter: "v"
  ],
  http: [port: 4001]
use Mix.Config

config :maru, MaruVersion.API,
  versioning: [
    using: :accept_version_header
  ],
  http: [port: 4001]

2. use version/1 or version/2 DSL

defmodule MaruVersion.API.V1 do
  use Maru.Router

  version "v1"

  desc "get v1"
  get do
    "It works V1!"
  end

  mount Maru.Version.API.Shared
end
defmodule MaruVersion.API.V2 do
  use Maru.Router

  version "v2" do
    desc "get v2"
    get do
      "It works V2!"
    end

    mount Maru.Version.API.Shared
  end
end

3. mount to top API router

defmodule MaruVersion.API do
  use Maru.Router

  mount MaruVersion.API.V1
  mount MaruVersion.API.V2
end

Version Extend

defmodule MaruVersion.API.V2 do
  use Maru.Router

  version "v2" do
    desc "get v2"
    get do
      "It works V2!"
    end

    get :extend do
      "This will be extended!"
    end

    get :no_extend do
      "This will NOT be extended!"
    end
  end
end
defmodule MaruVersion.API.V3 do
  # extend all
  version "v3", extend: "v2", at: MaruVersion.API.V2,
  
  # extend only 
  version "v3", extend: "v2", at: MaruVersion.API.V2, only: [
    get: "/extend/*",
  ]

  # extend except 
  version "v3", extend: "v2", at: MaruVersion.API.V2, except: [
    match: "/no_extend",
  ]

  # high priority
  get do
    "It works V3!"
  end
end