rest_created_path_resource.erl 872 B

1234567891011121314151617181920212223242526272829303132333435
  1. -module(rest_created_path_resource).
  2. -export([init/3]).
  3. -export([allowed_methods/2]).
  4. -export([content_types_provided/2]).
  5. -export([get_text_plain/2]).
  6. -export([post_is_create/2]).
  7. -export([content_types_accepted/2]).
  8. -export([post_text_plain/2]).
  9. -export([created_path/2]).
  10. init(_Transport, _Req, _Opts) ->
  11. {upgrade, protocol, cowboy_rest}.
  12. allowed_methods(Req, State) ->
  13. {[<<"HEAD">>, <<"GET">>, <<"POST">>], Req, State}.
  14. content_types_provided(Req, State) ->
  15. {[{{<<"text">>, <<"plain">>, []}, get_text_plain}], Req, State}.
  16. get_text_plain(Req, State) ->
  17. {<<"This is REST!">>, Req, State}.
  18. post_is_create(Req, State) ->
  19. {true, Req, State}.
  20. content_types_accepted(Req, State) ->
  21. {[{{<<"text">>, <<"plain">>, []}, post_text_plain}], Req, State}.
  22. post_text_plain(Req, State) ->
  23. {true, Req, State}.
  24. created_path(Req, State) ->
  25. {<<"/created">>, Req, State}.