How to get data from an API of the same origin?

60 views Asked by At

I have a route (/user/{id}) that returns user information in json format. I want to display some user info on my index(/) page. So, in my handler for the index(/), I have

const host ="https//www.example.com"
const url = host + "/user/1"
const response = await fetch(url, init)

But, the thing is that it hangs and times out. I guess it is because, it is still serving the request for the index page, which is also making another request to /user/{id}. So, the second request doesn't seem to be served as the handler is occupied by the first request in my opinion. Is there a way to fix this?

Thank you

0

There are 0 answers