Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

462
Views
Exception while consuming REST API from React JS

I have created a REST Endpoint in python application & it works fine when called from the browser. However, when I am trying to consume it in React JS application, it gives error on console.

I tried various ways for calling it as below.

  1. Plain Old Javascript
        var request = new XMLHttpRequest();
        request.open("GET", "http://127.0.0.1:5000/countries", true);
        request.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
        request.send(data);

Error in console: On last line of above code, getting :

"Failed to load resource: net::ERR_FAILED"

  1. Fetch method in REACT
fetch(apiUrl)
            .then((response) => response.json())
            .then((data) => console.log("This is your data", data));

Error in console: On last line of above code, getting :

"Failed to load resource: net::ERR_FAILED"

"Uncaught (in promise) TypeError: Failed to fetch

  1. Axios :
axios.get("http://127.0.0.1:5000/countries")
            .then(res => {
                const responseData = res.data;
                console.log("responseData is : ", responseData);
            });

Error in console :

Uncaught(in promise). -> AxiosError -> Network error

Axios Error snapshot

Is there any issue with network/proxy settings or any library?

I need to make GET requests first, then POST requests as well. Please suggest with an example.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

have you tried localhost instead of 127.0.0.1?

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!