Reap is a simple Elixir library for working with the refheap API. It uses the excellent hackney HTTP client and JSEX JSON encoder/decoder.
Reap only has one function you should care about: request/2
, request/3
.
Here's some examples:
As you can see, if the request and json decode is successful we get back {:ok, body}
. Let's see what happens if things go wrong:
iex(11)> Reap.request(:post, "/paste")
{:error, :refheap, [{"error", "Your paste cannot be empty."}]}
In this case, something went wrong on refheap and it gave us back an error. The
second element of the tuple is the type of the error, and it can be :refheap
if something bad happens on refheap, :json
if JSON parsing of the body fails
for some reason, or :http
if we fail to make an http request at all. In the
latter two cases, the entire hackney response gets returned as the third element
of the tuple.