Helios v0.1.0 Helios.Param protocol View Source

A protocol that converts data structures into URI parameters.

This protocol is used by URL helpers and other parts of the Helios stack. For example, if you call facade with:

YourApp.Facade.User.create_user(1, %{"first_name" => "Foo", last_name => "Bar", "email" => "foo@example.com"})

Helios knows how to extract the :id from first parameter thanks to this protocol. Since underneeth it will build path that will be used for routing

By default, Helios implements this protocol for integers, binaries, atoms, and structs. For structs, a key :id is assumed, but you may provide a specific implementation.

Nil values cannot be converted to param.

Custom parameters

In order to customize the parameter for any struct, one can simply implement this protocol.

However, for convenience, this protocol can also be derivable. For example:

defmodule CreateUser do
  @derive Helios.Param
  defstruct [:id, :username]
end

By default, the derived implementation will also use the :id key. In case the user does not contain an :id key, the key can be specified with an option:

defmodule CreateUser do
  @derive {Helios.Param, key: :username}
  defstruct [:username]
end

will automatically use :username in URLs.

Link to this section Summary

Link to this section Types

Link to this section Functions