Hi everybody,
I’m new in this programming language, my question is about create a simple http server.
For example in golang or nodeJs, I only need use owner http modules but in elixir I need cowboy? Plug? Potion?. I was reading about GenServer i don’t know if this is the answer. Thank for help me.
Sry but I’m not native speaker.
1 Like
The usual way to build http server is to use Phoenix, it uses cowboy under the hood.
But there are alternatives, like Raxx… or go bare with gen_tcp
2 Likes
There is built in module httpd
which provides very, very simple HTTP server. Think of it like Ruby’s WEBrick
or Python’s http.server
modules. This is very, very simple server that is not suitable for “real world” usage. On the other hand Cowboy, Raxx, Elli and others are much more powerful implementations with a lot of different features that can handle heavy loads, do pooling, proper error handling, etc.
Of course you can implement your own server on top of gen_tcp
(with or without ssl
module), but it would be NIH syndrome (unless you know what you are doing).
But if you want something that is super simple - plug and play - server, then you can use raw Plug directly. RN it has support only for Cowboy, but it is pretty solid implementation that will probably fit your use case in 100%. But nothing prevents you from using Cowboy directly.
4 Likes
Welcome @alxchoy!
Here is a great intro to Plug: https://elixirschool.com/en/lessons/specifics/plug/, a way of creating a minimal webserver.
For anything else, I’d strongly suggest looking at Phoenix: https://hexdocs.pm/phoenix/up_and_running.html#content
1 Like
Nice, thanks to everyone for your replies.