简体   繁体   中英

Phoenix - Access Erlang dependency

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM