diff options
Diffstat (limited to 'doc/src/guide')
-rw-r--r-- | doc/src/guide/getting_started.ezdoc | 2 | ||||
-rw-r--r-- | doc/src/guide/handlers.ezdoc | 16 | ||||
-rw-r--r-- | doc/src/guide/loop_handlers.ezdoc | 14 | ||||
-rw-r--r-- | doc/src/guide/middlewares.ezdoc | 2 | ||||
-rw-r--r-- | doc/src/guide/rest_handlers.ezdoc | 4 | ||||
-rw-r--r-- | doc/src/guide/sub_protocols.ezdoc | 8 | ||||
-rw-r--r-- | doc/src/guide/ws_handlers.ezdoc | 4 |
7 files changed, 25 insertions, 25 deletions
diff --git a/doc/src/guide/getting_started.ezdoc b/doc/src/guide/getting_started.ezdoc index a959b45..deb7bf2 100644 --- a/doc/src/guide/getting_started.ezdoc +++ b/doc/src/guide/getting_started.ezdoc @@ -121,7 +121,7 @@ start(_Type, _Args) -> Dispatch = cowboy_router:compile([ {'_', [{"/", hello_handler, []}]} ]), - cowboy:start_http(my_http_listener, 100, [{port, 8080}], + {ok, _} = cowboy:start_http(my_http_listener, 100, [{port, 8080}], [{env, [{dispatch, Dispatch}]}] ), hello_erlang_sup:start_link(). 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 diff --git a/doc/src/guide/loop_handlers.ezdoc b/doc/src/guide/loop_handlers.ezdoc index 879013b..47893a9 100644 --- a/doc/src/guide/loop_handlers.ezdoc +++ b/doc/src/guide/loop_handlers.ezdoc @@ -34,8 +34,8 @@ process enter hibernation until a message is received. This snippet enables the loop handler. ``` erlang -init(Req, Opts) -> - {cowboy_loop, Req, Opts}. +init(Req, _Opts) -> + {cowboy_loop, Req, #state{}}. ``` However it is largely recommended that you set a timeout @@ -43,8 +43,8 @@ value. The next example sets a timeout value of 30s and also makes the process hibernate. ``` erlang -init(Req, Opts) -> - {cowboy_loop, Req, Opts, 30000, hibernate}. +init(Req, _Opts) -> + {cowboy_loop, Req, #state{}, 30000, hibernate}. ``` :: Receive loop @@ -94,9 +94,9 @@ a chunk is sent every time a `chunk` message is received, and the loop is stopped by sending an `eof` message. ``` erlang -init(Req, Opts) -> - Req2 = cowboy_req:chunked_reply(200, [], Req), - {cowboy_loop, Req2, Opts}. +init(Req, _Opts) -> + Req2 = cowboy_req:chunked_reply(200, [], Req), + {cowboy_loop, Req2, #state{}}. info(eof, Req, State) -> {stop, Req, State}; diff --git a/doc/src/guide/middlewares.ezdoc b/doc/src/guide/middlewares.ezdoc index 35e9ea9..8b047d7 100644 --- a/doc/src/guide/middlewares.ezdoc +++ b/doc/src/guide/middlewares.ezdoc @@ -19,7 +19,7 @@ It is defined in the `cowboy_middleware` behavior. This callback has two arguments. The first is the `Req` object. The second is the environment. -Middlewares can return one of four different values: +Middlewares can return one of three different values: * `{ok, Req, Env}` to continue the request processing * `{suspend, Module, Function, Args}` to hibernate diff --git a/doc/src/guide/rest_handlers.ezdoc b/doc/src/guide/rest_handlers.ezdoc index e09790a..e6bb092 100644 --- a/doc/src/guide/rest_handlers.ezdoc +++ b/doc/src/guide/rest_handlers.ezdoc @@ -13,8 +13,8 @@ to all handlers. To use REST for the current request, this function must return a `cowboy_rest` tuple. ``` erlang -init(Req, Opts) -> - {cowboy_rest, Req, Opts}. +init(Req, _Opts) -> + {cowboy_rest, Req, #state{}}. ``` Cowboy will then switch to the REST protocol and start executing diff --git a/doc/src/guide/sub_protocols.ezdoc b/doc/src/guide/sub_protocols.ezdoc index d34f21e..54e57aa 100644 --- a/doc/src/guide/sub_protocols.ezdoc +++ b/doc/src/guide/sub_protocols.ezdoc @@ -14,8 +14,8 @@ the name of the sub protocol module. Everything past this point is handled by the sub protocol. ``` erlang -init(Req, Opts) -> - {cowboy_websocket, Req, Opts}. +init(Req, _Opts) -> + {cowboy_websocket, Req, #state{}}. ``` The return value may also have a `Timeout` value and/or the @@ -28,8 +28,8 @@ protocol, sets the timeout value to 5 seconds and enables hibernation: ``` erlang -init(Req, Opts) -> - {my_protocol, Req, Opts, 5000, hibernate}. +init(Req, _Opts) -> + {my_protocol, Req, #state{}, 5000, hibernate}. ``` If a sub protocol does not make use of these options, it should diff --git a/doc/src/guide/ws_handlers.ezdoc b/doc/src/guide/ws_handlers.ezdoc index 4cdf526..a0cfc29 100644 --- a/doc/src/guide/ws_handlers.ezdoc +++ b/doc/src/guide/ws_handlers.ezdoc @@ -16,8 +16,8 @@ to all handlers. To establish a Websocket connection, this function must return a `ws` tuple. ``` erlang -init(Req, Opts) -> - {cowboy_websocket, Req, Opts}. +init(Req, _Opts) -> + {cowboy_websocket, Req, #state{}}. ``` Upon receiving this tuple, Cowboy will switch to the code |