no need to write that much code to get requests using fetch.
get request is the default method. you can write just fetch(URL). for another type of requests you should write method, headers, body, etc.
just write this function and invoke it.
async function getData () {
const URL = 'your_url'
let response = await fetch(URL)
let data = await response.json()
console.log(data)
}
I am using an async await for fetching data. for any type of promise request you should use async await, this will help you to handle promises.