The typical way to use Cowboy, as described in the "Getting Started" documentation is to list it as a dependency in your .app
file. Doing this will inform the runtime that the Cowboy application needs to be started before your own application can start.
This setup is easy (one line in your .app
) and should generally be robust. Cowboy will restart crashed workers as needed, and your application doesn't really worry about it. Lots of other vital libraries (e.g. the kernel) are started this same way, so you're in good company.
However, it's possible that your application has some need to deeply entwine itself with Cowboy. Maybe you expect the entire Cowboy supervision tree to crash and you want to restart it? Or maybe you need to restart Cowboy when some process of yours dies?
For this, you'll want to look at cowboy_sup:start_link/0
and ranch_sup:start_link/0
.