Sometimes I just need to feed the SEO monster for Erlang. In this case, I could not find a good post that described doing an Erlang http:request that posts with a json payload. This is to support the BDD (“Cucumber but really fast”) testing framework that I’ve included in Crowbar.
Method = post, URL = "http://192,168.124.10:3000/node/2.0/new", Header = [], Type = "application/json", Body = "{\"name\":\"foo.example.com\"}", HTTPOptions = [], Options = [], R = httpc:request(Method, {URL, Header, Type, Body}, HTTPOptions, Options), {ok, {{"HTTP/1.1",ReturnCode, State}, Head, Body}} = R. {"id", Key} = lists:keyfind("id",1,json:parse(Body)),
Note: See the full source: https://github.com/crowbar/barclamp-crowbar/blob/master/BDD/digest_auth.erl
The Body will contain your JSON response and I used our Erlang json lib to parse that to find the ID.
In the actual BDD code, it’s a little more complex because I also use our Erlang digest auth. I hope this helps you!