pmjoe

pmjoe

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?

Showing Posts 1 to 10

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!

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
tomkonidas

tomkonidas

Usually I would reach for phoenix, but on occasion I have used bandit/plug for simple cases. For example I have an application and want to just expose 1-2 endpoints (like a health check or something of that sort.) I would find it overkill to pull phoenix deps in just for that, but if I am building something and expect to add more routes, I would just start with phoenix. You could generate the project without many of the other things you dont need, see JSON and APIs — Phoenix v1.8.8

dimitarvp

dimitarvp

You change the file structure any way you see fit. You have 99% freedom. Very little in Phoenix firmly expects this or that in that particular file (if any at all; now I can’t remember).

Phoenix or any framework is an overkill if you have like 2-10 endpoints and you don’t expect the app to change or expand anytime soon, or ever. As @tomkonidas said, if you expect expansion, go for Phoenix. Otherwise you can do fine with just Plug. I’ve done it successfully. It’s a little extra work but at small scales it does not matter and yeah, much less dependencies (though how much is that a true objective positive remains a forever open question).

BartOtten

BartOtten

Use Phoenix. Maybe you get some overhead but also a lot less to plump yourself.

And this is the only thing I ever used a bare server app for.

  • It was a single need_update? endpoint
  • which was missing features (e.g. request validation ) on purpose.
  • It only responded with a http status code, stripped from all optional (but common and advised) headers to save bandwidth.
  • no logging, minimizing IO

Most time of development was spend at research to minimize the payload.

Ask yourself: What makes you the most productive? A custom solution with no guidance (for you and your fellow (future) devs) or a fleshed out framework with guides all over the place? Quite sure Phoenix is the answer.

dimitarvp

dimitarvp

Well in this case I am not sure Elixir, or any dynamic language, is a good idea at all.

Just use https://gofiber.io/, you can make an “app” with 3 endpoints literally in 15 minutes. Single binary, cross-compilation supported out of the box, faster than Elixir too (if that even matters for these bare apps).

BartOtten

BartOtten

Does it come with ETS and supervisors? Also much easier to be able to use Cachex.

So maybe that other option is even faster but the load test failed too make impact. In the end the load testing company i worked for (so could go full scale for free) ran out of agents. And we ran tests for (inter)national voting events so it was not a small scale (virtual) server park.

Now I think of it, initially there was confusion if the test was pointing at the right IP, as I was looking at the load charts for CPU and memory and they did not seem to respond to the ramp up phase :smiley:

Productivity wise, I think the Elixir app nailed it and as it passed the test with flying colors…

dimitarvp

dimitarvp

I don’t think we are talking micro apps here anymore then. :smiley:

FlyingNoodle

FlyingNoodle

An entire phoenix application can fit into a single file with roughly 60 lines of code, including dependencies, router, etc.

Like… how much smaller do you want it?

I will post a code snippet when I’m on my computer.

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
peck
Hi everyone. My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
bradley
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
Alvinkariuki
How Can I Optimise Compile Time Dependencies I have been building an elixir application for about 2 years now. Many modules and files ha...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews