Phoenix port to a Flask App - phoenix 1.2

Any suggestions/ repos on how to call an external flask app from an elixir port? Would I go about using Porcelain?

My main doubt is, we need to access the flask app, which is inside an venv and then send a request. A general starting point would also do!

Thanks!

If it is already running then I’d use HTTPoison or so just to make the request.

If it is not running then you can use erl_exec or porcelein or so to run it, but flask is designed to run in a wsgi container so I’d just have it run in that. If you want to run it ‘from’ elixir then just run it as you do from a shell, then use something like HTTPoison to make a web request to it.

Just started with this, trying to learn. So spoiler alert for some stupid questions.

My flask app consumes an external api and parses the json and gives me the required info - a list of 10 users.
Now I would like to click on a button in my elixir/phoenix app, and obtain this list of 10 users. I would proceed to store the list in my elixir/phoenix app and work with it.

The flask app does not run unless you click on the said button inside the elixir app. Can I still use porcelain or erl_exec?

Thanks!

If the flask app is not already running then how is it receiving the callbacks from the external API?

Or if the external API is queryable directly, why not just access it directly?

It seems really really round-about to spool up another web server just to have it listen for a remote API to call back to it? And if it can query the remote server it seems even more not useful to spawn another web server that will be serving nothing at all (in which case just call the python script that calls the external API and have it return the json over stdout)?

But yes, just seems way way convoluted?

The external api is oauth accessible only. Specifically this:
https://developer.intuit.com/docs/api/accounting

I am just afraid I would bite into more than i can chew, if I start querying this external API directly. Hence using their readily available SDK.

Oh so it is a pull interface they give, not a push, you definitely don’t need flask then. I’d just make a python script to use their API to pull data then return it as JSON over stdout, you can do that all via just a normal BEAM Port, no external libraries needed then. You could even go more fancy and leave that script always running and just send requests to it that it then returns. :slight_smile:

3 Likes

Oh that does sound simpler. Thanks for the replies and patience! :slight_smile:

2 Likes

Forgive my ignorance but how would you set the script to always be running? Would you use something like genserver or make the Python script in such a way that it’s always active with something like upstart? What would you recommend?

Specifically a GenServer wrapping a Port, that is the most common usage of a Port as well. :slight_smile:

Thank you!