Created
February 24, 2022 22:30
-
-
Save MeerKatDev/29d6d632725f93ae7ba1732b0b1434d6 to your computer and use it in GitHub Desktop.
simple starting code for using :httpc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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