diff options
author | Loïc Hoguin <[email protected]> | 2015-02-16 18:03:35 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2015-02-16 18:03:35 +0100 |
commit | 4f2bbd2e5a08e10f98fc82c1f0a98a7c8649b3ee (patch) | |
tree | 0eaa05fc247994ac6f01f51c1979f7b321ca260c /doc/src/guide/handlers.ezdoc | |
parent | 410662b29589214c1d825a027ec6b195c23e3ad6 (diff) | |
parent | 8fd3ff2d629fa13a52061e7db5c67a3ba6fe4429 (diff) | |
download | cowboy-4f2bbd2e5a08e10f98fc82c1f0a98a7c8649b3ee.tar.gz cowboy-4f2bbd2e5a08e10f98fc82c1f0a98a7c8649b3ee.tar.bz2 cowboy-4f2bbd2e5a08e10f98fc82c1f0a98a7c8649b3ee.zip |
Merge branch 'master' of https://github.com/sstrigler/cowboy
Diffstat (limited to 'doc/src/guide/handlers.ezdoc')
-rw-r--r-- | doc/src/guide/handlers.ezdoc | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/doc/src/guide/handlers.ezdoc b/doc/src/guide/handlers.ezdoc index c0fb97e..9336488 100644 --- a/doc/src/guide/handlers.ezdoc +++ b/doc/src/guide/handlers.ezdoc @@ -14,8 +14,8 @@ defined during the ^"router configuration^routing^. A handler that does nothing would look like this: ``` erlang -init(Req, Opts) -> - {ok, Req, Opts}. +init(Req, _Opts) -> + {ok, Req, #state{}}. ``` Despite sending no reply, a `204 No Content` reply will be @@ -25,11 +25,11 @@ sent for every request. We need to use the Req object for sending a reply. ``` erlang -init(Req, Opts) -> +init(Req, _Opts) -> Req2 = cowboy_req:reply(200, [ {<<"content-type">>, <<"text/plain">>} ], <<"Hello World!">>, Req), - {ok, Req2, Opts}. + {ok, Req2, #state{}}. ``` As you can see we return a 3-tuple. `ok` means that the @@ -60,15 +60,15 @@ return the name of the handler type you want to use. The following snippet switches to a Websocket handler: ``` erlang -init(Req, Opts) -> - {cowboy_websocket, Req, Opts}. +init(Req, _Opts) -> + {cowboy_websocket, Req, #state{}}. ``` You can also switch to your own custom handler type: ``` erlang -init(Req, Opts) -> - {my_handler_type, Req, Opts}. +init(Req, _Opts) -> + {my_handler_type, Req, #state{}}. ``` How to implement a custom handler type is described in the |