[erlang-questions] Cowboy: init and handle — how to use them?
Wed Dec 26 17:03:09 CET 2012
I'm looking at
it looks like all logic should be done in rest_init with rendering in
On Wed, Dec 26, 2012 at 7:48 PM, Loïc Hoguin <> wrote:
> On 12/26/2012 04:23 PM, Max Lapshin wrote:
>> Loic, would you kindly explain what are the exact rules to split code
>> between init/3 and handle/2?
>> Frankly speaking, I never use terminate, because I also doesn't
>> understand what is it for, but most interesting is the question about
>> init and handle.
>> Where should I put database select, for example?
> In handle.
> It works like a gen_server with few differences. In init you would
> initialize the state if needed (plain HTTP requests may not need it, other
> kinds probably do), check that the request looks good and inform Cowboy
> what kind of handler this is. In handle you do whatever you need to do with
> the request. In terminate you cleanup. Like with gen_server, terminate will
> rarely do anything because most of the time when you need to clean things
> up you just have monitors reporting this process is 'DOWN' and do the
> cleanup there instead.
> Loïc Hoguin
> Erlang Cowboy
> Nine Nines
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions