2013-02-15 22:41:55 +07:00
|
|
|
-module(rest_param_all).
|
|
|
|
|
2014-09-26 15:58:44 +03:00
|
|
|
-export([init/2]).
|
2013-02-15 22:41:55 +07:00
|
|
|
-export([allowed_methods/2]).
|
|
|
|
-export([content_types_provided/2]).
|
|
|
|
-export([get_text_plain/2]).
|
|
|
|
-export([content_types_accepted/2]).
|
|
|
|
-export([put_text_plain/2]).
|
|
|
|
|
2014-09-26 15:58:44 +03:00
|
|
|
init(Req, Opts) ->
|
2014-09-30 20:12:13 +03:00
|
|
|
{cowboy_rest, Req, Opts}.
|
2013-02-15 22:41:55 +07:00
|
|
|
|
|
|
|
allowed_methods(Req, State) ->
|
|
|
|
{[<<"GET">>, <<"PUT">>], Req, State}.
|
|
|
|
|
|
|
|
content_types_provided(Req, State) ->
|
|
|
|
{[{{<<"text">>, <<"plain">>, '*'}, get_text_plain}], Req, State}.
|
|
|
|
|
|
|
|
get_text_plain(Req, State) ->
|
2014-09-23 16:43:29 +03:00
|
|
|
{_, _, Param} = cowboy_req:meta(media_type, Req, {{<<"text">>, <<"plain">>}, []}),
|
2013-02-15 22:41:55 +07:00
|
|
|
Body = if
|
2014-09-23 16:43:29 +03:00
|
|
|
Param == '*' ->
|
|
|
|
<<"'*'">>;
|
|
|
|
Param == [] ->
|
|
|
|
<<"[]">>;
|
|
|
|
Param /= [] ->
|
|
|
|
iolist_to_binary([[Key, $=, Value] || {Key, Value} <- Param])
|
2013-02-15 22:41:55 +07:00
|
|
|
end,
|
2014-09-23 16:43:29 +03:00
|
|
|
{Body, Req, State}.
|
2013-02-15 22:41:55 +07:00
|
|
|
|
|
|
|
content_types_accepted(Req, State) ->
|
|
|
|
{[{{<<"text">>, <<"plain">>, '*'}, put_text_plain}], Req, State}.
|
|
|
|
|
|
|
|
put_text_plain(Req, State) ->
|
|
|
|
{true, Req, State}.
|