0dc063a Sep 30, 2014
40 lines (32 sloc) 857 Bytes
%% Feel free to use, reuse and abuse the code in this file.
%% @doc Hello world handler.
init(Req, Opts) ->
{cowboy_rest, Req, Opts}.
content_types_provided(Req, State) ->
{<<"text/html">>, hello_to_html},
{<<"application/json">>, hello_to_json},
{<<"text/plain">>, hello_to_text}
], Req, State}.
hello_to_html(Req, State) ->
Body = <<"<html>
<meta charset=\"utf-8\">
<title>REST Hello World!</title>
<p>REST Hello World as HTML!</p>
{Body, Req, State}.
hello_to_json(Req, State) ->
Body = <<"{\"rest\": \"Hello World!\"}">>,
{Body, Req, State}.
hello_to_text(Req, State) ->
{<<"REST Hello World as text!">>, Req, State}.