pmjoe

pmjoe

For a pure JSON API application, is Phoenix overkill?

In case I need to build a JSON API is Phoenix overkill? I don’t quite like the way Phoenix is structured, it remembers me a lot Rails, and given the fact that I just need to expose an JSON API, is Phoenix overkill? Or let me put better, do you see any limitations on using Plug and a router directly?

First Post!

hubertlepicki

hubertlepicki

Phoenix is using Plug. If you’re okay with hooking up everything yourself, there’s no problem just going with Plug, and Cowboy/Bandit directly.

I would not do it, and most people would not do it too probably, because it may prove to be extra work nobody wants to do, and end result being inferior to what Phoenix provides out of the box anyway, but people have free will and if - for example - it’s a learning exercise - go for it!

Most Liked

LostKobrakai

LostKobrakai

It’s so interesting how on the one hand people ask for more and more structure guidance within phoenix and then on the other hand it’s held against it.

There’s two parts to the structure discussion. There’s your business logic, where phoenix really doesn’t care what you do. And there’s the my_app_web layer, where again phoenix doesn’t care, but I’d argue conventions are useful for the next person and having worked on other phoenix projects might give you a leg up. Ultimately you can setup your files in whatever structure you want still.

Even though a JSON api won’t necessarily use all the features of phoenix I still think there are a few very useful ones, which would be missing in a bare bandit/plug setup, like the code reloader, features of the router/endpoint and their testing helpers, all the url handling/generation stuff phoenix provides, the error page, …

10
Post #2
tomekowal

tomekowal

is Phoenix overkill?

I believe that question is a result of carrying misconceptions from other languages or frameworks which oftentimes add code bloat and performance penalty. Phoenix is not like that. E.g. in Ruby world, you often see discussion about choosing Rails (heavyweight but complete) vs Sinatra (lightweight, requiring more from the user, but not carrying over bloat).

This dichotomy does not exist in Phoenix. The next sentence is a little stretch, but it should give a nice intuition. In the sense of lightness Plug might be comparable to Sinatra. Now, imagine if Rails was just a generator for a full blown app that glues some Sinatra configs together. Then you could use the quick start convention and remove all the unnecessary stuff.

That is exactly how Phoenix works. It is a layer on top of Plug with conventions and configurations. Even better, you don’t need to start with full Phoenix and remove stuff, the mix phx.new task allows specifying –-no-assets –-no-html –-no-live and you are ready to go.

So, in the end, use Phoenix. It is not like Rails which would pull a lot of unnecessary things. Phoenix can be as lean as you need it while benefitting from easy to follow conventions. It is even fine to use Phoenix to server static content with -–no-ecto.

Last Post!

manhvu

manhvu

I use Phoenix + Ash that is a perfect couple. Just declarative then get almost APIs That I needed.

In my case, I use Phoenix in my some projects just for transportation throw Phoenix channel before that I have used for JSON API. Phoenix still benefit for me like authentication, verification and encoding/decoding between JSON and Elixir structures.

Where Next?

Popular in Questions Top

lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Other popular topics Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New

We're in Beta

About us Mission Statement