Created
October 28, 2011 14:56
-
-
Save pragmaticobjects/1322467 to your computer and use it in GitHub Desktop.
Routing in cowboy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| start(_Type, _Args) -> | |
| Dispatch = [ | |
| {'_', [ | |
| {[<<"users">>, id, <<"messages">>], users_handler, []}, | |
| {'_', default_handler, []} | |
| ]} | |
| ], | |
| cowboy:start_listener(http, 100, | |
| cowboy_tcp_transport, [{port, 8080}], | |
| cowboy_http_protocol, [{dispatch, Dispatch}] | |
| ), | |
| Then in users_handler.erl, | |
| handle(Req, State) -> | |
| {Value, Req2} = cowboy_http_req:binding(id, Req), | |
| case Value of | |
| <<"messages">> -> | |
| {ok, Req3} = cowboy_http_req:reply(200, [], <<"Hello world!">>, Req), | |
| {ok, Req3, State}, | |
| _ -> | |
| ... | |
| end. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment