Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -module(rest_handler).
- -export([init/2,allowed_methods/2,content_types_provided/2]).
- -export([content_types_accepted/2]).
- -export([hello_json/2,hello_post/2]).
- init(Req, State) ->
- {cowboy_rest, Req, State}.
- allowed_methods(Req, State) ->
- {[<<"GET">>,<<"POST">>], Req, State}.
- % {[{{<<"application">>, <<"x-www-form-urlencoded">>, '*'}, create_paste}],
- % Req, State}.
- content_types_accepted(Req, State) ->
- {[
- {<<"application/json">>, hello_post}
- ],Req, State}.
- content_types_provided(Req, State) ->
- {[
- {<<"application/json">>, hello_json}
- ], Req, State}.
- hello_json(Req,State) ->
- {<<"{\"rest\": \"Hello World!\"}">>,Req,State}.
- hello_post(Req,State) ->
- {ok,Body,Req1} = cowboy_req:read_body(Req),
- io:format("~p~n",[Body]),
- {true, cowboy_req:reply(201, Req1), State}.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement