diff options
author | Loïc Hoguin <[email protected]> | 2013-01-18 17:07:46 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2013-01-18 17:07:46 +0100 |
commit | 1476b13ca0e19daf97548c0d47fe648d438985ef (patch) | |
tree | c00cfc9c8dd4c8c07849803c5096edb79e916346 /guide/http_handlers.md | |
parent | 6f552005f274cc6d9056b49dc6c9cee26cb8577f (diff) | |
download | cowboy-1476b13ca0e19daf97548c0d47fe648d438985ef.tar.gz cowboy-1476b13ca0e19daf97548c0d47fe648d438985ef.tar.bz2 cowboy-1476b13ca0e19daf97548c0d47fe648d438985ef.zip |
Add plain HTTP handlers documentation to the guide
Diffstat (limited to 'guide/http_handlers.md')
-rw-r--r-- | guide/http_handlers.md | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/guide/http_handlers.md b/guide/http_handlers.md index 0d8886d..ea88c79 100644 --- a/guide/http_handlers.md +++ b/guide/http_handlers.md @@ -6,12 +6,22 @@ Purpose HTTP handlers are the simplest Cowboy module to handle a request. -Callbacks ---------- - -@todo Describe the callbacks. - Usage ----- -@todo Explain how to use them. +You need to implement three callbacks for HTTP handlers. The first, +`init/3`, is common to all handlers. In the context of HTTP handlers +this should be used for any initialization needs. + +The second callback, `handle/2`, is where most of your code should +be. As the name explains, this is where you handle the request. + +The last callback, `terminate/2`, will be empty most of the time. +It's used for any needed cleanup. If you used the process dictionary, +timers, monitors then you most likely want to stop them in this +callback, as Cowboy might end up reusing this process for subsequent +requests. Please see the Internals chapter for more information. + +Of course the general advice is to not use the process dictionary, +and that any operation requiring reception of messages should be +done in a loop handler, documented in its own chapter. |