From 666c59bc422172562673916ed3a8a796c4f9fbf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Fri, 17 May 2013 13:13:27 +0200 Subject: Add the Cowboy Function Reference The manual details every stable public functions of Cowboy. --- manual/cowboy_http_handler.md | 57 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 manual/cowboy_http_handler.md (limited to 'manual/cowboy_http_handler.md') diff --git a/manual/cowboy_http_handler.md b/manual/cowboy_http_handler.md new file mode 100644 index 0000000..9d283e7 --- /dev/null +++ b/manual/cowboy_http_handler.md @@ -0,0 +1,57 @@ +cowboy_http_handler +=================== + +The `cowboy_http_handler` behaviour defines the interface used +by plain HTTP handlers. + +Unless noted otherwise, the callbacks will be executed sequentially. + +Types +----- + +None. + +Callbacks +--------- + +### init({TransportName, ProtocolName}, Req, Opts) + -> {ok, Req, State} | {shutdown, Req, State} + +> Types: +> * TransportName = tcp | ssl | atom() +> * ProtocolName = http | atom() +> * Req = cowboy_req:req() +> * Opts = any() +> * State = any() +> +> Initialize the state for this request. +> +> The `shutdown` return value can be used to skip the `handle/2` +> call entirely. + +### handle(Req, State) -> {ok, Req, State} + +> Types: +> * Req = cowboy_req:req() +> * State = any() +> +> Handle the request. +> +> This callback is where the request is handled and a response +> should be sent. If a response is not sent, Cowboy will send +> a `204 No Content` response automatically. + +### terminate(Reason, Req, State) -> ok + +> Types: +> * Reason = {normal, shutdown} | {error, atom()} +> * Req = cowboy_req:req() +> * State = any() +> +> Perform any necessary cleanup of the state. +> +> This callback should release any resource currently in use, +> clear any active timer and reset the process to its original +> state, as it might be reused for future requests sent on the +> same connection. Typical plain HTTP handlers rarely need to +> use it. -- cgit v1.2.3