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:

https://github.com/wojtekmach/mix_install_examples/blob/727e0a70aeb194593eac913afc224c5c0e0f09ea/plug_cowboy.exs

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?

Where Next?

Popular in Questions Top

chokchit
** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2733ms. You can configure how long re...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
Kurisu
For example for a current url like http://localhost:4000/cosmetic/products?_utf8=✓&query=perfume&page=2, I would like to get: ...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lists...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> somethi...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

Other popular topics Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
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
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31142 143
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New

We're in Beta

About us Mission Statement