pmjoe

pmjoe

Good example of plug based web application

Does anyone know any good example of web applications without Phoenix? I think Elixir is so damn simple, but every time I create a Phoenix project is just too much. I just want to do something with Ecto, Plug, and Htmx.

Marked As Solved

LostKobrakai

LostKobrakai

I‘d suggest differentiating phoenix the library from code, which is generated by phoenix generators. Because most of what the latter provides is not set in stone as all.

It‘s one way of doing things, which caters best to the usecase of powering crud generators for people trying to quickly scaffold apps. You‘re free if not encouraged to adjust those things to fit whatever else you need.

Also Liked

LostKobrakai

LostKobrakai

This sentiment surely comes up regularly, but having seen people attempt this over the years I‘m not sure skipping phoenix (the library) is worth it.

Plug for simple stuff can be quite simple code and less files, but on the other hand any more advanced stuff will need you to write more code than you‘d need to write with phoenix around. Like doing a redirect needs you to manually deal with location headers and also will be missing the security validation phoenix does for local paths. I‘ve seen similar things quite a bit over the years where people ask how to do a thing they know is simple from phoenix in a bare plug app, where it turns out having phoenix would‘ve been the simpler answer.

Phoenix can be stripped down quite a lot, you can use a plug router on a phoenix endpoint without issues (if you‘re not using router mounted LVs) and you‘ll still have most of the functionality of phoenix around.

10
Post #4
dimitarvp

dimitarvp

@wojtekmach’s repository of single-file apps might be very helpful to you:

It was for me.

Yeah, same here. I admire the work of the Phoenix team, I simply wish we had PhoenixLite or something. :smiley:

mayel

mayel

This is mentioned often and I wonder if simply highlighting the --no-* options in the getting started guide would help, because a lot of Phoenix is optional:

  • --no-assets - equivalent to --no-esbuild and --no-tailwind
  • --no-dashboard - do not include Phoenix.LiveDashboard
  • --no-ecto - do not generate Ecto files
  • --no-esbuild - do not include esbuild dependencies and assets. We do not recommend setting this option, unless for API only applications, as doing so requires you to manually add and track JavaScript dependencies
  • --no-gettext - do not generate gettext files
  • --no-html - do not generate HTML views
  • --no-live - comment out LiveView socket setup in assets/js/app.js. Automatically disabled if --no-html is given
  • --no-mailer - do not generate Swoosh mailer files
  • --no-tailwind - do not include tailwind dependencies and assets. The generated markup will still include Tailwind CSS classes, those are left-in as reference for the subsequent styling of your layout and components

Edit: these are the files created when you use all those flags:

mix phx.new phoenix_lite_example --no-assets --no-dashboard --no-ecto --no-gettext --no-html --no-mailer
* creating phoenix_lite_example/lib/phoenix_lite_example/application.ex
* creating phoenix_lite_example/lib/phoenix_lite_example.ex
* creating phoenix_lite_example/lib/phoenix_lite_example_web/controllers/error_json.ex
* creating phoenix_lite_example/lib/phoenix_lite_example_web/endpoint.ex
* creating phoenix_lite_example/lib/phoenix_lite_example_web/router.ex
* creating phoenix_lite_example/lib/phoenix_lite_example_web/telemetry.ex
* creating phoenix_lite_example/lib/phoenix_lite_example_web.ex
* creating phoenix_lite_example/mix.exs
* creating phoenix_lite_example/README.md
* creating phoenix_lite_example/.formatter.exs
* creating phoenix_lite_example/.gitignore
* creating phoenix_lite_example/test/support/conn_case.ex
* creating phoenix_lite_example/test/test_helper.exs
* creating phoenix_lite_example/test/phoenix_lite_example_web/controllers/error_json_test.exs
* creating phoenix_lite_example/priv/static/robots.txt
* creating phoenix_lite_example/priv/static/favicon.ico

Edit 2: These are the dependencies included:

  • phoenix
  • telemetry_metrics
  • telemetry_poller
  • jason
  • dns_cluster
  • bandit

And the extra dependencies in lockfile:

  • castore
  • hpax
  • mime
  • phoenix_pubsub
  • phoenix_template
  • plug
  • plug_crypto
  • telemetry
  • thousand_island
  • websock
  • websock_adapter

So apart from adding a --no-telemetry flag I’m not sure how much lighter it could reasonably get while still being sensible?

mtrudel

mtrudel

Creator of Bandit

If you’ve not already, I highly recommend taking a look at Plug.Router; it’s very much Elixir’s sinatra.

dimitarvp

dimitarvp

I am strictly focusing on amount of files, not the removal of features, some of which are critical for most commercial projects (like HTML/templating and DBs/Ecto). Phoenix projects have way too many files IMO.

I know that people who constantly work on Phoenix apps have gotten used to it but as a guy who is leaning on the backend side of things, Phoenix’s generated files relating to UI are confusing.

F.ex. I fail to see point of views to this day. Surely for a lot of projects you can always rely on the defaults that are injected in your code by the generator but these view files are just kind of… sitting there. They are basically an artifact of the framework’s chosen abstractions that leak into your project’s source code.

I’d try to do without them as a start and see how far I can take it.

Where Next?

Popular in Questions Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
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
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
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
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
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
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
hpopp
To simplify some tasks at work, I wrote and published this package yesterday. It’s a simple macro that enables Access behaviour on struct...
New

Other popular topics Top

yurko
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
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
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

We're in Beta

About us Mission Statement