aboutsummaryrefslogtreecommitdiffstats
path: root/README.md
diff options
context:
space:
mode:
authorAnthony Ramine <[email protected]>2011-04-30 12:28:07 +0200
committerAnthony Ramine <[email protected]>2011-04-30 12:32:43 +0200
commit2c21f0cd09041ee96ed99fdb109b173cd1993fc9 (patch)
treebbdf2c1f146724a1d1bd3070175bc2e880fccb85 /README.md
parent20293be9128fd6ecbb5db9bd40fbd4ca8581a4ce (diff)
downloadcowboy-2c21f0cd09041ee96ed99fdb109b173cd1993fc9.tar.gz
cowboy-2c21f0cd09041ee96ed99fdb109b173cd1993fc9.tar.bz2
cowboy-2c21f0cd09041ee96ed99fdb109b173cd1993fc9.zip
Use syntax highlighted code block in README.md
GitHub just implemented that and we should use it. https://github.com/blog/832-rolling-out-the-redcarpet
Diffstat (limited to 'README.md')
-rw-r--r--README.md42
1 files changed, 23 insertions, 19 deletions
diff --git a/README.md b/README.md
index a3551b3..cebe45a 100644
--- a/README.md
+++ b/README.md
@@ -54,30 +54,34 @@ listener a unique name.
Code speaks more than words:
- application:start(cowboy),
- Dispatch = [
- %% {Host, list({Path, Handler, Opts})}
- {'_', [{'_', my_handler, []}]}
- ],
- %% Name, NbAcceptors, Transport, TransOpts, Protocol, ProtoOpts
- cowboy:start_listener(http, 100,
- cowboy_tcp_transport, [{port, 8080}],
- cowboy_http_protocol, [{dispatch, Dispatch}]
- ).
+``` erlang
+application:start(cowboy),
+Dispatch = [
+ %% {Host, list({Path, Handler, Opts})}
+ {'_', [{'_', my_handler, []}]}
+],
+%% Name, NbAcceptors, Transport, TransOpts, Protocol, ProtoOpts
+cowboy:start_listener(http, 100,
+ cowboy_tcp_transport, [{port, 8080}],
+ cowboy_http_protocol, [{dispatch, Dispatch}]
+).
+```
You must also write the `my_handler` module to process requests. You can
use one of the predefined handlers or write your own. An hello world HTTP
handler could be written like this:
- -module(my_handler).
- -export([init/3, handle/2, terminate/2]).
+``` erlang
+-module(my_handler).
+-export([init/3, handle/2, terminate/2]).
- init({tcp, http}, Req, Opts) ->
- {ok, Req, undefined}.
+init({tcp, http}, Req, Opts) ->
+ {ok, Req, undefined}.
- handle(Req, State) ->
- {ok, Req2} = cowboy_http_req:reply(200, [], "Hello World!", Req),
- {ok, Req2, State}.
+handle(Req, State) ->
+ {ok, Req2} = cowboy_http_req:reply(200, [], "Hello World!", Req),
+ {ok, Req2, State}.
- terminate(Req, State) ->
- ok.
+terminate(Req, State) ->
+ ok.
+```