aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_http_handler.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2011-07-06 17:42:20 +0200
committerLoïc Hoguin <[email protected]>2011-07-06 17:42:20 +0200
commit108a491f5515fdc2a7fe3ce8c310a261d6be3230 (patch)
tree74fb2109c6b193c382a0712a053702b3ec240a13 /src/cowboy_http_handler.erl
parent2b3bfdd783915b263ed3fdfd6e135b9a84982821 (diff)
downloadcowboy-108a491f5515fdc2a7fe3ce8c310a261d6be3230.tar.gz
cowboy-108a491f5515fdc2a7fe3ce8c310a261d6be3230.tar.bz2
cowboy-108a491f5515fdc2a7fe3ce8c310a261d6be3230.zip
Add documentation for the public interface.
This is probably not perfect yet but it should be better than nothing. We'll improve things with feedback received from the many users.
Diffstat (limited to 'src/cowboy_http_handler.erl')
-rw-r--r--src/cowboy_http_handler.erl25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/cowboy_http_handler.erl b/src/cowboy_http_handler.erl
index 67f07bc..b220b09 100644
--- a/src/cowboy_http_handler.erl
+++ b/src/cowboy_http_handler.erl
@@ -12,9 +12,34 @@
%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+%% @doc Handler for HTTP requests.
+%%
+%% HTTP handlers must implement three callbacks: <em>init/3</em>,
+%% <em>handle/2</em> and <em>terminate/2</em>, called one after another in
+%% that order.
+%%
+%% <em>init/3</em> is meant for initialization. It receives information about
+%% the transport and protocol used, along with the handler options from the
+%% dispatch list, and allows you to upgrade the protocol if needed. You can
+%% define a request-wide state here.
+%%
+%% <em>handle/2</em> is meant for handling the request. It receives the
+%% request and the state previously defined.
+%%
+%% <em>terminate/2</em> is meant for cleaning up. It also receives the
+%% request and the state previously defined.
+%%
+%% You do not have to read the request body or even send a reply if you do
+%% not need to. Cowboy will properly handle these cases and clean-up afterwards.
+%% In doubt it'll simply close the connection.
+%%
+%% Note that when upgrading the connection to WebSocket you do not need to
+%% define the <em>handle/2</em> and <em>terminate/2</em> callbacks.
-module(cowboy_http_handler).
+
-export([behaviour_info/1]).
+%% @private
-spec behaviour_info(_)
-> undefined | [{handle, 2} | {init, 3} | {terminate, 2}, ...].
behaviour_info(callbacks) ->