Plug provides a unified API for connecting Elixir web applications to HTTP servers and composing request middleware without exposing the underlying server implementation. With plug_cowboy, applications access Cowboy through Plug rather than calling Cowboy directly. section 11.3.1
A Plug.Cowboy child specification turns server options into a supervised HTTP-server component. The supervision tree can start listeners and request processes while keeping connection-management details behind Plug. section 11.3.2
Request handling combines router macros with explicit connection operations:
- use Plug.Router, then apply plug :match and plug :dispatch to establish routing behavior. section 11.3.3
- Define post and get clauses for paths such as /add_entry and /entries; Plug generates route-dispatch functions from these macros. section 11.3.3
Minimal supervised server
Declare {:plug_cowboy, "~> 2.6"}, return Plug.Cowboy.child_spec(scheme: :http, options: [port: 5454], plug: __MODULE__), and add the module to the supervision tree.
