0

I want t make a http request like this:

 const fun = (params) => {
    fetch(`${params.url}`, {
        method: "get",
        mode: 'cors', 
        headers: {
            'Content-Type': 'application/json',
            ...params.headers,
        },
        body: JSON.stringify(params.body)
    })
        .then((response) => {
            return response.json();
        })
        .then((data) => {
            return data
        }).catch(err => {
        return Promise.reject(err);
    });
};



console.log(fun({
  url: "https://jsonplaceholder.typicode.com/todos/1"
}))

Why i get undefined and what should change to make the code workable?

Asking
  • 3,487
  • 11
  • 51
  • 106

0 Answers0