How to specify default parameters for controller actions

At SO, I have found this solution:

  def by_code(conn, %{"code" => code} = params, user) do
    prefix = Map.get(params, "prefix", nil) # prefix has a default value

But is there any better way to do this?

You could merge the params with the defaults:

defaults = %{ "prefix" => nil }
params = Map.merge(defaults, params)

Or you can define Ecto embedded_schema for the params and supply a default value for each field.