rest_forbidden_resource.erl 805 B

1234567891011121314151617181920212223242526272829303132
  1. -module(rest_forbidden_resource).
  2. -export([init/2]).
  3. -export([allowed_methods/2]).
  4. -export([forbidden/2]).
  5. -export([content_types_provided/2]).
  6. -export([content_types_accepted/2]).
  7. -export([to_text/2]).
  8. -export([from_text/2]).
  9. init(Req, [Forbidden]) ->
  10. {cowboy_rest, Req, Forbidden}.
  11. allowed_methods(Req, State) ->
  12. {[<<"GET">>, <<"HEAD">>, <<"POST">>], Req, State}.
  13. forbidden(Req, State=true) ->
  14. {true, Req, State};
  15. forbidden(Req, State=false) ->
  16. {false, Req, State}.
  17. content_types_provided(Req, State) ->
  18. {[{{<<"text">>, <<"plain">>, []}, to_text}], Req, State}.
  19. content_types_accepted(Req, State) ->
  20. {[{{<<"text">>, <<"plain">>, []}, from_text}], Req, State}.
  21. to_text(Req, State) ->
  22. {<<"This is REST!">>, Req, State}.
  23. from_text(Req, State) ->
  24. {{true, cowboy_req:path(Req)}, Req, State}.