Reputation: 8404
I'm using Phoenix (v1.2.1) to build a REST API, but I know very little about Elixir and pretty much zero about Erlang.
As part of the create
action on one of my controllers, group_controller.ex
, I need to query an external source to generate some data. The logic for producing this query is in an Erlang dependency that has been added to my mix.exs
deps and successfully installed in the deps
directory... so that is all good.
However, I haven't the slightest idea how to import the module or access its functionality in my controller (or anywhere in my app, for that matter). Can I even use an Erlang dependency out of the box in a Phoenix app, or does it need to be transpiled to Elixir?
If I were writing this in ES6, I would write something like
import {FunctionA, FunctionB} from 'module'
easy as pie... how can I accomplish that in Phoenix when the dependency is written in Erlang?
Thank you!
Upvotes: 2
Views: 177
Reputation: 75740
Erlang modules are accessible as atoms
of their module names in elixir, and you can call their methods like any other Modules:
:module.function(arguments)
For Example:
To call the uniform/0
method of the Erlang random
module, you can do this:
:random.uniform
Upvotes: 4