Learning Strategy for the Cowboy Elixir Plug

I’m trying to use elixir from time to time and have a use case for something simpler than Phoenix (=> Cowboy).

I was wondering how people know how to use the Cowboy Elixir Plug?

I find a lot of secondary content (blog posts etc.) but I would like to understand how to figure it out by myself.

The documentation of the plug itself is small and the Cowboy Library itself is in Erlang.

Can people infer from the (Erlang) Cowboy documentation how to use the Cowboy Plug or do they read the code or how does it work?

1 Like

This could be featured a bit more prominently, but you can find an example of how to start things on the child_spec/1 function: Plug.Cowboy — Plug.Cowboy v2.7.5

There’s not much more to know as you can e.g see here: mix_install_examples/plug_cowboy.exs at main · wojtekmach/mix_install_examples · GitHub

Generally I’d however suggest skipping cowboy alltogether and use bandit as an elixir dev. It’s written in elixir and specifically for plug. Cowboys erlang documentation is basically useless for the use with plug, as it’s not written for plug. You need plug_cowboy to translate between plug and cowboy.

3 Likes

Ah thanks for clarification (and pointing me to bandit)! I took a deeper look at the Plug package and it turn’s out that the code I wondered about was mostly related to Plug and not Cowboy. The routing definitions for example.

If you are still looking for cowboy based examples, this book covers good part of it - Build Your Own Web Framework in Elixir | Web Development | Paperback