create_resource_h.erl 646 B

12345678910111213141516171819202122232425262728
  1. -module(create_resource_h).
  2. -export([init/2]).
  3. -export([allowed_methods/2]).
  4. -export([resource_exists/2]).
  5. -export([content_types_accepted/2]).
  6. -export([from_text/2]).
  7. init(Req, Opts) ->
  8. {cowboy_rest, Req, Opts}.
  9. allowed_methods(Req, State) ->
  10. {[<<"POST">>], Req, State}.
  11. resource_exists(Req, State) ->
  12. {true, Req, State}.
  13. content_types_accepted(Req, State) ->
  14. {[{{<<"application">>, <<"text">>, []}, from_text}], Req, State}.
  15. from_text(Req=#{qs := Qs}, State) ->
  16. NewURI = [cowboy_req:uri(Req), "/foo"],
  17. case Qs of
  18. <<"created">> ->
  19. {{created, NewURI}, Req, State};
  20. <<"see_other">> ->
  21. {{see_other, NewURI}, Req, State}
  22. end.