[erlang-questions] Store / use JSON structure in an nice way ?

Thomas Elsgaard thomas.elsgaard@REDACTED
Mon Jun 15 19:07:11 CEST 2015


Hi list

I am using hackney as http client (due to PATCH support), and i have an
JSON structure in the Payload, this works very well, but it is not feeling
really "good" to have the JSON structure in the code, and i will also need
to have some variables in the JSON structure instead of only hardcoded
values. What is the correct erlangish way to handle the JSON payload, is it
really to have in the code as i have it now, or can it be placed in an
record ?

Here is the code:

Method = patch,
URL = <<"http://2.2.2.2:8081/servers/localhost/zones/xxx.gl">>,
Headers = [{<<"X-API-Key">>, <<"xxxxxxxx">>}],
Payload = <<"{\"rrsets\":[{\"name\": \"xxx.gl\",\"type\":
\"A\",\"changetype\": \"REPLACE\",\"records\": [{\"content\":
\"1.1.1.1\",\"disabled\":false,\"name\": \"xxx.gl\",\"ttl\":
\"3600\",\"type\": \"A\",\"priority\": \"0\"}]}]}">>,
Options = [],
{ok, StatusCode, RespHeaders, ClientRef} = hackney:request(Method, URL,
Headers, Payload, Options).

Any hints so that it looks nice ;-)

Thomas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150615/c57afab2/attachment.htm>


More information about the erlang-questions mailing list