Packages

This package is used for learning purposes on how to use 'mix' and 'hex' for sharing elixir code. Do NOT waste your time here. The License is MIT, but the project uses a private api.

Current section

Files

Jump to
cape lib Arpas REST Generico api.ex
Raw

lib/Arpas/REST/Generico/api.ex

defmodule Arpas.REST.Generico.Api do
def post(url, payload) do
headers = [
{"Accept", "application/json"},
{"Content-Type", "application/x-www-form-urlencoded"},
{"Cache-Control", "no-cache, no-store, must-revalidate"},
]
result =
case HTTPoison.post(url, payload , headers) do
{:ok, %HTTPoison.Response{status_code: 200, body: body}} ->
body
{:ok, %HTTPoison.Response{status_code: 404}} ->
IO.puts "Not found :("
{:error, %HTTPoison.Error{reason: reason}} ->
IO.inspect reason
end
result
end
def get(url) do
headers = [
{"Accept", "application/json"},
{"Content-Type", "application/x-www-form-urlencoded"},
{"Cache-Control", "no-cache, no-store, must-revalidate"},
]
result =
case HTTPoison.get(url, headers) do
{:ok, %HTTPoison.Response{status_code: 200, body: body}} ->
Poison.decode(body)
{:ok, %HTTPoison.Response{status_code: 404}} ->
IO.puts "Not found :("
{:error, %HTTPoison.Error{reason: reason}} ->
IO.inspect reason
end
result
end
end