charsets_provided_h.erl 711 B

12345678910111213141516171819202122232425262728
  1. %% This module has a text and non-text media type,
  2. %% and provides two charsets.
  3. -module(charsets_provided_h).
  4. -export([init/2]).
  5. -export([content_types_provided/2]).
  6. -export([charsets_provided/2]).
  7. -export([get_text_plain/2]).
  8. -export([get_application_json/2]).
  9. init(Req, Opts) ->
  10. {cowboy_rest, Req, Opts}.
  11. content_types_provided(Req, State) ->
  12. {[
  13. {{<<"text">>, <<"plain">>, []}, get_text_plain},
  14. {{<<"application">>, <<"json">>, []}, get_application_json}
  15. ], Req, State}.
  16. charsets_provided(Req, State) ->
  17. {[<<"utf-8">>, <<"utf-16">>], Req, State}.
  18. get_text_plain(Req, State) ->
  19. {<<"This is REST!">>, Req, State}.
  20. get_application_json(Req, State) ->
  21. {<<"{\"hello\": \"rest\"}">>, Req, State}.