In my free time I am learning elixir, and now I am trying to develop simple Elixir API. Everything works fine, besides when I try to insert new values using Postman/curl. When I'm trying to do so with such data:
{
"tree": "nil",
"value": "5"
}
I get this error: (FunctionClauseError) no function clause matching in Access.get/3
.
Here is my code for POST in my Endpoint.
post "/insert" do
IO.inspect(conn.body_params)
{status, body} =
case conn.body_params do
%{"tree" => tree, "value" => value} -> {200, process_insert(tree, value)}
BstInsertion.insert(tree, value)
_ -> {400, missing_insert()}
end
send_resp(conn, status, body)
end
Example of insert function and process_insert:
def insert(nil, value) do
%{value: value, ltree: nil, rtree: nil}
end
defp process_insert(_tree, _value) do
Poison.encode!(%{response: "Received insert!"})
end
If this is not enough, I will provide more code. Thank you for any advice and help.