Phoenix vs. Plug for Website and Mobile App

I’ve got a design question for you guys. I’m building a service in Elixir which requires inputs from users (a web interface) and also sends and receives JSON requests from third-party APIs (webhooks). We want this service available to users through a website and mobile app. Phoenix seems to be the natural choice for the former with it’s browser and api pipelines. However, when interfacing with a mobile app, it seems like creating a RESTful API using Plug is most suitable. My question: is it necessary to build a Phoenix web framework and Plug API separately with redundant functionality, or just build a RESTful API in Plug, or is there a better way to accomplish both?



I personally have been doing something like this (unsure how ‘standard’ it is, but these forums do it and it is natively supported in Phoenix):

https://mysite/ -> Returns the index html
https://mysite/?_format=json -> Returns the data of the index page in json format

And so forth (although more data like ‘v’ for version arguments are accepted or latest if unspecified).
I’ve actually been looking at that GraphQL(sp?) or whatever it was lately, it looks interesting for when the client wants only specific things…


The HTTP oriented parts of Phoenix are all 100% just plugs themselves. Phoenix works very well for JSOn apis, and gives you a number of conveniences you’re gonna miss by just using Plug.


Gotcha. I was thinking along those lines. Is there anything out there on making Elixir applications with a mobile app front end using iOS or Android? Would these mobile apps interface with the Elixir application using a standard HTTP API? I’m wondering how Phoenix and Plug might fit in here.

Standard rest api’s are fine. Could use websockets if you need the speed (though what a hit to battery if constantly on). Depends on your uses? For example:

Is it just a website front-end? Just make a mobile website then.
Is it extra functionality? If Notifications then use a notification service for the given platform (web calls are battery unfriendly for those). If just for a better interface but is otherwise sporadically used then REST or websockets depending on need.

Either way, phoenix can host it all.

The interest in a mobile app over a mobile website is to improve the user experience along with sending push notifications. I’m a little unclear on what the endpoint of my application should be if I want to have a mobile app be the user interface (with the aforementioned functionality). I’m also a bit of a newb :wink:

Well a pure json ‘API’ path would be the more usual (code should not be duplicated in any case between it and controllers, if it is then you need to move more code into lib and call those from the controllers). GraphQL would allow the mobile app to only request what it actually needs at that second so might make a better endpoint?

1 Like

Thanks for the info! I’ll look into this more.

I’m working on one, and using a plain old ‘boring’ HTTP API :wink: As @benwilson512 mentions, Phoenix offers a number of handy conveniences you can utilize.

Nice, as an interface for a mobile app?