Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Erlang 0.82 KB | None | 0 0
  1. -module(rest_handler).
  2.  
  3. -export([init/2,allowed_methods/2,content_types_provided/2]).
  4. -export([content_types_accepted/2]).
  5. -export([hello_json/2,hello_post/2]).
  6.  
  7. init(Req, State) ->
  8.     {cowboy_rest, Req, State}.
  9.  
  10. allowed_methods(Req, State) ->
  11.     {[<<"GET">>,<<"POST">>], Req, State}.
  12.  
  13.     % {[{{<<"application">>, <<"x-www-form-urlencoded">>, '*'}, create_paste}],
  14.     %   Req, State}.
  15. content_types_accepted(Req, State) ->
  16. {[
  17.     {<<"application/json">>, hello_post}
  18. ],Req, State}.
  19.  
  20. content_types_provided(Req, State) ->
  21.     {[
  22.         {<<"application/json">>, hello_json}
  23.      ], Req, State}.
  24.  
  25. hello_json(Req,State) ->
  26.     {<<"{\"rest\": \"Hello World!\"}">>,Req,State}.
  27.  
  28. hello_post(Req,State) ->
  29.     {ok,Body,Req1} = cowboy_req:read_body(Req),
  30.     io:format("~p~n",[Body]),
  31.     {true, cowboy_req:reply(201, Req1), State}.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement