Home > Back-end >  Fetch data from Api in react
Fetch data from Api in react

Time:03-17

I want to fetch the data from this api (refer the screenshots) in reactjs using fetch function..I tried different ways but none of them is working

I am doing this way

useEffect(() => {
    // POST request using fetch inside useEffect React hook
    const requestOptions = {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ "firebase_id":"fonnnnjnvQXzyOcXK5kW88PM8jnjnhnhb1"})
    };
    fetch('demo.revon.com/audi/zero/li', requestOptions)
        .then(response => response.json())
        .then(data =>  console.log(data));                 

CodePudding user response:

You should try to call your API without https://localhost:3000 in front of your API link.

You forgot to put HTTP or HTTPS so it consider a subfolder of localhost:3000.

You must do something like that : (or http if not https)

fetch('https://demo.revon.com/audi/zero/li', requestOptions)
        .then(response => response.json())
        .then(data =>  console.log(data));    

Regards

CodePudding user response:

You’ll need to mention https:// in the fetch url

CodePudding user response:

requestOptions is not the issue here!


You are OBVIOUSLY hitting the localhost domain, not demo.revon.
Insert the full URL: https://demo.revon.com/audi/zero/li

  • Related