Unexpected results with HTTPoison

Am new to Elixir ,so am trying to create a function that uses HTTPoison to fetch the link .
The expected output when I call the function is suppose to appear this way:

%HTTPoison.Response{
 body: "<!doctype html>...",
headers: [    
  {"Content-Type", "text/html"},..],  

  request: %HTTPoison.Request{

   body: "",
 headers: [],
method: :get,
options: [],
params: %{},
url: "https://medium.."

This is how my code looks like:

def fetch_blog() do
    HTTPoison.get!("https://medium.com"
    )
        t()::%HTTPoison.Response{
          body:term(),
          headers:list(),
          request:HTTPoison.Request.t(),
          request_url:HTTpoison.Request.url(),
          status_code:integer()
     }
end

Where could I have got it wrong please!

1 Like

Hello and welcome,

Please don’t forget to wrap your code with 3 backticks ``` for better readability. I made the change so You can see the difference.

What is the result, or error when You call your function?

1 Like

This probably causes a syntax error, there is no need to have the typedefinition listed there, you can remove it, such that your function looks like this:

def fetch_blog() do
  HTTPoison.get!("https://medium.com")
end

HTTPoison.get!/1s returned value should look exactly like you specified.

3 Likes