I’m fooling around with Cowboy, and the Getting Started guide has you build the src files with:
% make run
That takes 10-20 seconds on my system. That’s pretty intolerable when trying to write code. Is there a way to avoid having to rebuild the whole thing when I edit my src files?
I ended up following a tutorial on setting up cowboy in a Docker container using rebar3. I’m not using a Docker container, so what I ended up with is a rebar3 app with cowboy as a dependency. Thereafter, when I execute rebar3 shell, that starts a cowboy server and opens a shell in the terminal window. Then if I go into another terminal window and send a request to the url specified in my cowboy code, I get the expected response.
Here are the steps:
$ rebar3 new app my_cowboy_server
$ cd my_cowboy_server
In the file my_cowboy_server/rebar.config, add cowboy as a dependency:
If you want/need to use the template generating capabilities of Erlang.mk, for instance to create hello_handler.erl, you could follow the cowboy Getting Started guide and create the hello_erlang release, then any time you need a template switch into that directory, generate the template, copy it, modify the module name, etc., then move it into your rebar3 app.
The command rebar3 shell compiles and executes the same code in about 1 second compared to 30-40 seconds for Erlang.mk. Of course, rebar3 shell is not creating a release, but if you want to experiment with cowboy, then a rebar3 app seems like the best way to quickly compile and execute your code.