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

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
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
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews