The Elixir Outlaws now have a Patreon. If you’re enjoying the show then please consider throwing a few bucks our way to help us pay for the costs for the show.
Elixir Outlaws, 09/02/2022
On today’s episode of the Elixir Outlaws, Amos and Sean are going to talk about what other models and frameworks are out there for building web apps. The plug has some stuff that looks like Sinatra, but the responses were not what Sean expected in some places. Many people recommended the web machine and the surprising elixir plug. A big point of a web machine is to build something that conforms to the semantics in the RFCs as much as possible. It’s kind of hard for most web frameworks Sean has used, aside from web machines.
In a web machine, your resources are the main thing you work with, and it is a module with a bunch of optional callbacks that you can implement. In a web machine, you have controllers, routers, and dispatch lists that you match over.
If you have designed the thing right, you can do that computation at a very low cost to the server. So you are generally improving things in terms of bandwidth, but you are also improving things in terms of time spent processing the request, says Sean.
The e-tags are a little bit more complicated, but you could do something like hash the contents of the record and use that as an E-tag. Sometimes you can’t, but that happens all before you even get to the point of producing content.
Elli is another great Erling Web server and what’s great about it is super tiny. You can do a lot with very, very little code, and like a phoenix or plug, it will compile your routes when you define them, explains Sean.
You can just give ELLI a list of functions, and it’ll run all of them and pass them whatever the output is from the previous function. The only requirement is your end handler because the thing attached to the route has to return particular keys in that map, suggests Amos.
Ease is a big deal for people. If you understand any language or server, you can get into this new language or new framework pretty easily with ease.
It’s hard to get started or figure out whenever you run into problems. The lifecycle stuff is spread out all over the documentation because sometimes you can change web sockets so that it’ll react, and sometimes you can’t flash messages the same way, says Amos.
When you are trying to load your timeline on the big social media websites, you get some placeholder thing first, and then they load in, and it displays, suggests Sean.
There are some limitations to the bandit framework yet. It’s not 100% complete, but it can probably work for most of the Phoenix things or plug things you want to do, says Sean.
When Amos first started looking into Erling, they looked into Erling for a communication server, not a web server.
Nitrogen hails from the days before we have WebSockets, but a lot of what it was trying to do is very much in line with things like live view things, says Sean.
3 Key Points
Many people know phoenix but don’t know Elixir, and similarly mid-teen people with Ruby projects don’t know Rails or don’t use the things that the language provides.
If you know Elixir well enough, the big Leap is not semantics for Erling, but the syntax. Erling doesn’t apply to Elixir because it made different choices, making the Erling web server less approachable to work on.
The flip side of nitrogen is that it’s inefficient to render the tricks that EEX does. Where it’s like I’m going to read everything up until this sigil, and that’s going to be one binary that gets submitted into the compiled function, says Sean.
“With rails, It was hard to do computation because you’d have to go all the way down into the controller and do all of the work you are going to do except rendering the page.’ - Sean
“If you focus on doing very little in each callback defined by the web machine, you get a snappy and compliant HTTP interface.” – Sean
“If your whole page is a live view and the initial render is even really just an empty template that maybe check some authentication to make sure that you are off.” - Amos
Elixir Outlaws: Website