I am making call to HTTP Rest API in elixir
url = "http://localhost:8080/getScoreData"
case HTTPoison.get(url) do
{:ok, %{status_code: 200, body: body}} ->
Logger.info("body is #{inspect(body)}")
overall_score = Jason.decode!(body, as: [%OverallScore{}])
{:ok, overall_score}
end
which in the web browser returns
{
"avgPass": 85.55,
"avgFail": 14.45,
"totalStudents": 80.0,
"myScoreSchema": [
{
"average": 80.0,
"count": 8.0,
"percent": 80.0,
"name": "John"
},
{
"average": 0.0,
"count": 0.0,
"percent": 0.0,
"name": "Cena"
},
{
"average": 0.0,
"count": 0.0,
"percent": 0.0,
"name": "Sunny"
},
{
"average": 0.0,
"count": 0.0,
"percent": 0.0,
"name": "Michael"
}
]
}
but the log as of the line Logger.info("body is #{inspect(body)}") from above code dedups
the data and returns below data instead
{
"avgPass": 85.55,
"avgFail": 14.45,
"totalStudents": 80.0,
"myScoreSchema": [
{
"average": 80.0,
"count": 8.0,
"percent": 80.0,
"name": "John"
},
{
"average": 0.0,
"count": 0.0,
"percent": 0.0,
"name": "Cena Sunny Michael"
}
]
}
Even though this is a smart feature but I don't want this dedup feature. How to avoid the dedup.
To eliminate whether or not HTTPoison is really deduping or not, you can use elixir to get the raw response back first:
Define your test request with:
And finally, you can use Elixir/Erlang to call your endpoint:
This should get you what you're seeing in the browser, at which point you can parse it however your heart desires.
But as soon as you try to convert it using Poison.decode, keep in mind that it likely will dedupe your data, as it might treat duplicated keys as updates to the values, rather than allowing duplicate keys to exist in a map.