jarmo

jarmo

Hello!

I’ve been an avid Phoenix user for years now (let’s say ~4-5 years?). Have multiple installations running in production etc. I also have Ruby on Rails experience a way back (from Rails 4 already if I remember correctly up to Rails 6). Total professional programming experience is ~15 years and has been mostly about web-apps.

Usually when I use these frameworks which do all the things, I start to wonder at one point, how difficult would it be to create a web application using lower level tools instead of these heavy-weight champions. I’m happy to say that I find Phoenix much more lightweight compared to Rails, however it still gets once in a while in my way with weird problems, which are harder to grasp due to the overhead and creates additional work with its backwards-incompatible version releases if there is any urge to upgrade. In Ruby ecosystem I would use Sinatra (or something similar) with some templating engine and lower-level database-connection library to build a web application if I would not want to use Rails.

I’ve never done something similar in Elixir world yet, but started to think what does Phoenix offer me in the first place. As I understand then one big thing about Phoenix is LiveView, but I’ve never found a use for it since I like more “boring technologies” meaning server-side template rendering and only a little bit of JavaScript here and there where more dynamic functionality is needed (surprise, surprise - most of the time it is not needed). And of course Phoenix-like framework offers conventions of where to put your code, which is really good if you’re just starting coding career.

I started to ponder that thought a little bit more and found out that most of the things I thought being part of Phoenix is just part of Elixir itself (thing Config and Releases for example).

After some initial research I found out that I could use Plug with Cowboy, Config, Releases and EEx together with Ecto and its migrations. I would also like not to use Ecto and use something where I can write plain old SQL, but have not found anything to my liking yet in Elixir ecosystem.

Any thoughts or experience about going this road or any strong opinions against doing it? What does Phoenix offer in your mind, which is not easy to do when not using Phoenix? Any good light-weight library suggestions (especially about database related)?

Don’t get me wrong - Phoenix is a fantastic framework, which has managed to create a fork of RoR in a good way. Usually these forks fail miserably in other ecosystems/programming languages because for some reason good parts of RoR is not copied and many bad parts are copied instead :slight_smile: Thank you for Phoenix!

Jarmo

Showing Posts 1 to 10

josevalim

josevalim

Creator of Elixir

You should be able to get something quickly up and running using Plug (Plug.Router in particular) and Phoenix.Template+Phoenix.HTML (if you are doing HTML stuff). If you are doing APIs, then you will need Jason and a handful of helpers such as json/2, which receives the connection, data, and renders it as JSON. For queries, you can use Postgrex directly.

jarmo

jarmo OP

Thank you @josevalim for quick reply.

Why would you recommend using Phoenix.Template+Phoenix.HTML instead of plain old EEx? Can’t I just go with EEx for some reason?

And for Postgrex it seemed to me at first that it’s not that easy to use transactions and pooling (need to use ecto-dbconnection for that). Do you have any good guides for that? Also database migrations seem to require ecto-migration.

jchrist

jchrist

If you just want to run plain SQL you can use your database driver directly - for example, when you use PostgreSQL, Ecto uses postgrex under the hood. You could also try Erlang’d ODBC, I haven’t used it personally yet though :slight_smile:

As for light-weight library suggestions for the HTTP server itself, I’ve recently had good luck when building a simple mnesia benchmarking tool with using Erlang’s built-in HTTP server with mod_esi. You basically need to start :httpd with a config that tells it where to find your Erlang Script Interface (ESI) modules (Erlang Syntax):

    ServiceConfig = [
        {port, 4000},
        {bind_address, {127, 0, 0, 1}},
        {server_name, "mnesia_bench"},
        {document_root, filename:join(Here, "public")},
        {directory_index, ["index.html"]},
        {mime_types, [{"html", "text/html"}, 
                      {"css", "text/css"},
                      {"js", "application/javascript"}]},
        {server_root, "/tmp"},
        {error_log, "error.log"},
        {erl_script_alias, {"/esi", [mnesia_bench_esi]}}
    ],
    {ok, _Pid} = inets:start(httpd, ServiceConfig),

then if the mnesia_bench_esi module exports a function create_table/3, you can call it from your browser at the URL /esi/mnesia_bench_esi:create_table. I found this pretty simple to quickly build something with, and :httpd is pretty configurable, but it won’t compare with Phoenix of course :grin:

D4no0

D4no0

You can, however template engine used by phoenix first of all is html aware and secondly it generates safe escaped html so you don’t have things like XSS attacks.

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Yeah it’s this bit specifically that makes EEx on its own a non starter for any app that will display user data.

An alternative over “raw” postgrex is to still use ecto, but only set up a repo and do migrations with it. You can do Repo.query or Repo.all(from u in "users", ...) and skip all the schema / changeset stuff if you want. This gets you all of the valuable things ecto does from a safety / migration / core ergonomics standpoint.

jarmo

jarmo OP

Thanks for the tip, already checked Phoenix.HTML code and it should be really trivial to take only relevant parts from there. For example form/tag builders are not needed when using “boring technologies”.

jarmo

jarmo OP

This is maybe too low-level already, but good thoughts anyway. I’d prefer Plug since it also offers Plug.Test and other nice things while still being quite low-level, but not too low.

al2o3cr

al2o3cr

IMO about 80% of the developer effort spent on “keeping things lightweight” is waste; there was a huge fad back in the day of people going to incredible lengths to prove “they didn’t NEED a framework” that led to a lot of hard-to-maintain messes. I’ve worked on at least one $BIGCO codebase where they started by embedding Sinatra “to make an efficient API” then welded every other Rails feature back on.

IMO it’s good for everybody, because people farther along in their coding career should probably be thinking about “how to solve the customer’s problems” and less about “how to shuffle around some files”.

11
Post #8
sodapopcan

sodapopcan

I’m only weighing in because you say you like “boring technologies” and the whole reason I use LiveView is because I consider it a “boring technology”. It gets out of my way more than any other framework I’ve used and is quite a bit simpler than controller+view. There are also fewer things to learn than in other frameworks. If you’re used to building apps with “sprinkles of JavaScript” it even abstracts away most of those sprinkles (what’s less than a sprinkle? lol). Also, LiveView templates are server-rendered. I would at least give it a chance!

dimitarvp

dimitarvp

You’ll end up reinventing a smaller buggier Phoenix IMO.

I too think Phoenix can be too heavyweight on management – several different files in the right places, magic configurations with several levels of lists and tuples, code generators that historically have ended up producing outdated code you have to manually upgrade, and others I can’t remember right now – so I’ve been in projects where we’ve only used Plug for routing. However, these projects were serving JSON and had zero visual parts.

As much as I feel working with Phoenix is boring and annoying, it’s probably one of the best things we have on the planet in the web area.

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 92995 915
New
caslu
I want to open this thread for you all to discuss and help those who really like Ash but are still hesitant to use it in a real project. ...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
Herve37
We’re evaluating API mocking tools for OpenAPI-based projects and would love to hear what other teams are using. We’re particularly inte...
New
GES233
I’m posting this in response to Jose’s recent tweet (Cr. link) : People are sleeping on Elixir for a coding harness: Hot-code swappi...
New
_mfierro
Hello, I wrote Stop My Hand, a Scattergories-like web application using Phoenix/LiveView as my learning project for Elixir (after readin...
New
nseaSeb
AcmeScript — Writing JS hooks as if I were still using Elixir I’ve been having fun building a little something over the last few days: Ac...
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