Skip to content

Commit 9cab05e

Browse files
committed
README.md: update
1 parent 309648e commit 9cab05e

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

README.md

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# elli_websocket
22

3-
*A WebSocket handler for [Elli](https://github.com/elli-lib/elli)*
3+
*A WebSocket handler for [elli][]*
44

55
[![Erlang][erlang badge]][erlang downloads]
66
[![Travis CI][travis badge]][travis builds]
77
[![Coverage Status][coveralls badge]][coveralls link]
88
[![Apache License][license badge]](LICENSE)
99

10+
[elli]: https://github.com/elli-lib/elli
1011
[erlang badge]: https://img.shields.io/badge/erlang-%E2%89%A518.0-red.svg
1112
[erlang downloads]: http://www.erlang.org/downloads
1213
[travis builds]: https://travis-ci.org/elli-lib/elli_websocket
@@ -18,46 +19,55 @@
1819

1920
## Installation
2021

21-
You can add `elli_websocket` to your application by adding it as a dependency to your elli
22-
application.
22+
You can add `elli_websocket` to your application by adding it as a dependency to
23+
your [elli][] application.
2324

2425
```erlang
2526
{deps, [
26-
{elli_websocket, ".*", {git, "git://github.com/elli-lib/elli_websocket.git", {branch, "master"}}}
27+
{elli, "2.0.1"},
28+
{elli_websocket, "0.1.0"}
2729
]}.
2830
```
2931

3032

31-
## Callback Module
33+
## Examples
34+
35+
### Callback Module
3236

3337
See [elli_example_websocket.erl](./src/elli_example_websocket.erl) for details.
3438

3539
```erlang
3640
-module(elli_echo_websocket_handler).
37-
-export([websocket_init/1, websocket_handle/3, websocket_info/3, websocket_handle_event/3]).
41+
42+
-export([websocket_init/1,
43+
websocket_handle/3,
44+
websocket_info/3,
45+
websocket_handle_event/3]).
46+
3847

3948
websocket_init(Req, Opts) ->
4049
State = undefined,
4150
{ok, [], State}.
4251

52+
4353
websocket_handle(_Req, {text, Data}, State) ->
4454
{reply, {text, Data}, State};
4555
websocket_handle(_Req, {binary, Data}, State) ->
4656
{reply, {binary, Data}, State};
4757
websocket_handle(_Req, _Frame, State) ->
4858
{ok, State}.
4959

60+
5061
websocket_info(Req, Message, State) ->
5162
{ok, State}.
5263

64+
5365
websocket_handle_event(Name, EventArgs, State) ->
5466
ok.
5567
```
5668

5769

58-
## Upgrading to WebSocket Connection
59-
60-
This is an example of how you can upgrade to a WebSocket connection.
70+
### Upgrading to a WebSocket Connection
6171

6272
```erlang
6373
-module(elli_echo_websocket).
@@ -68,6 +78,7 @@ This is an example of how you can upgrade to a WebSocket connection.
6878

6979
-behaviour(elli_handler).
7080

81+
7182
init(Req, Args) ->
7283
Method = case elli_request:get_header(<<"Upgrade">>, Req) of
7384
<<"websocket">> ->
@@ -76,6 +87,7 @@ init(Req, Args) ->
7687
ignore
7788
end.
7889

90+
7991
handle(Req, Args) ->
8092
Method = case elli_request:get_header(<<"Upgrade">>, Req) of
8193
<<"websocket">> ->
@@ -85,9 +97,11 @@ handle(Req, Args) ->
8597
end,
8698
handle(Method, elli_request:path(Req), Req, Args).
8799

100+
88101
handle_event(_Event, _Data, _Args) ->
89102
ok.
90103

104+
91105
%%
92106
%% Helpers
93107
%%
@@ -97,17 +111,16 @@ init_ws([<<"echo_websocket">>], _Req, _Args) ->
97111
init_ws(_, _, _) ->
98112
ignore.
99113

114+
100115
handle('websocket', [<<"echo_websocket">>], Req, Args) ->
101116
%% Upgrade to a websocket connection.
102117
elli_websocket:upgrade(Req, Args),
103118

104119
%% websocket is closed.
105120
{close, <<>>};
106-
107121
handle('GET', [<<"echo_websocket">>], _Req, _Args) ->
108122
%% We got a normal request, request was not upgraded.
109123
{200, [], <<"Use an upgrade request">>};
110-
111124
handle(_,_,_,_) ->
112125
ignore.
113126
```

0 commit comments

Comments
 (0)