Skip to content

Instantly share code, notes, and snippets.

@MeerKatDev
Created February 24, 2022 22:30
Show Gist options
  • Save MeerKatDev/29d6d632725f93ae7ba1732b0b1434d6 to your computer and use it in GitHub Desktop.
Save MeerKatDev/29d6d632725f93ae7ba1732b0b1434d6 to your computer and use it in GitHub Desktop.
simple starting code for using :httpc
# first, add :inets to :extra_applications or some other similar method
defp simple_http_request(request, http_method) do
Application.ensure_all_started(:inets)
Application.ensure_all_started(:ssl)
ok_block = {'HTTP/1.1', 200, 'OK'}
options = [{:ssl, [{:verify, :verify_none}]}]
with {:ok, {^ok_block, _headers, json_text}} <-
:httpc.request(http_method, request, options, []),
{:ok, json_map} <- Jason.decode(json_text) do
json_map
else
err -> err
end
end
simple_http_request(:get, {"https://api.some.com", [{"accept", "application/json"}])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment