2
votes

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!

1
Have you tried :module.functionA(args) ? Post details of the module/method you want to use, so we can better answer you question.Sheharyar
@Sheharyar Wow, thank you! I didn't realize that it would be that easy - this works perfectly. Can you rephrase that as an answer and submit below so I can accept it?skwidbreth

1 Answers

4
votes

Calling Methods on Erlang Modules

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