I'm trying to implement Rest handler and have next code:
-module(example_handler).
-behaviour(cowboy_handler).
-export([init/2,
allowed_methods/2,
content_types_provided/2,
get_json/2]).
init(Req, State) ->
{cowboy_rest, Req, State}.
allowed_methods(Req, State) ->
io:format("allowed_methods~n"),
{[<<"GET">>, <<"POST">>], Req, State}.
content_types_provided(Req, State) ->
io:format("content_types_provided~n"),
{[{{<<"application">>, <<"json">>, []}, get_json}], Req, State}.
get_json(_Req, _State) ->
io:format("get_json~n")
Then when I try to send request with curl like that:
curl -H "Accept: application/json" -X POST http://localhost:8080/xxx/xx
I get next output:
allowed_methods
content_types_provided
get_json() is not called! But when I use GET method everything looks ok:
curl -H "Accept: application/json" -X GET http://localhost:8080/xxx/xx
----------------------------------------------------------------------
allowed_methods
content_types_provided
get_json
What I missed?