Erlang httpc for noobies? Getting exception error: no function clause matching httpc:request

-module(main).
-export([call_api/0]).

call_api() -> 
    {ok, Body} = httpc:request(get, {"http://api.ipify.org", []}, [], []),
    Body.

hi erlang noobie here, I’d like to understand what I am doing wrong here?
I also tried it like this

call_api() -> 
    {ok, Body} = httpc:request(get, {"http://api.ipify.org"}),
    Body.

but its throwing the following error:
** exception error: no function clause matching httpc:request(get,{get,[]},[],[],{“http://api.ipify.org”,[]}) (httpc.erl, line 157)
in function main:call_api/0 (main.erl, line 5)

1 Like

This seems good to me, what error do you get when calling this? Make sure that “inets” application is started before using httpc. This should make it more clear to you: Erlang -- HTTP Client . Try running the examples from section 3.2 .

This one is wrong because ‘httpc:request/2’ takes Url and Profile as parameters, not Method and Url.

1 Like