supervised inets httpd process

Ryan Zezeski <>
Sun Jun 27 20:37:48 CEST 2010


Hi everyone.  I'm a newcomer to Erlang and have been reading through
Programming Erlang for the past week.  There is an application I want to
build to replace a legacy webapp in my workplace.  I will be replacing the
bulk of this application with CouchDB/Erlang but I need a light web
interface that wraps it to provide service to the legacy endpoints (URLs).

As a first cut, I plan on using the inets application with a custom httpd
callback module to service the API.  I was curious, what is the best way to
"embed" the httpd server in my application?  That is, I'm building an OTP
compliant application, and I want the httpd server to sit under my
supervisor.

My first attempt was to create a gen_server callback that called
inets:start/1 and httpd:start/2 in the init/1 function, but I'm not sure
this was the appropriate approach.  My second approach was to start inets in
the supervisor callback init/1, and then pass the httpd startup to the
supervisor config like so: {inets, start, [httpd,[{port,7777}, ...}.

I'm not sure either approach is the correct one.  What I *think* I want is a
supervised process that contains the httpd server. I want this to be a
"permanent" process that is restarted when an error occurs.  I peeked at the
OTP source code a bit on github and noticed there is an httpd_manager which
implements gen_server.  Would this be more appropriate?

Before anyone mentions them, I am aware of Yaws and Mochiweb, but for my
proof of concept I want to stick with inets.

I appreciate any help and I just want to say that Erlang has been an
absolute joy so far!

-Ryan


More information about the erlang-questions mailing list