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

319
Views
Axios GET request working in plain js but not working in react - CORS error

When I make a GET request inside in react, I get blocked by CORS policy error. However if I make the same request inside vanilla js (a simple .js file) I get the appropriate response.

Here is my code in the react:

const axios = require('axios');

function getLatestPrice() {
  const config = {
    url: 'https://api.kraken.com/0/public/Trades?pair=ETHUSDT&since=1656322000',
    method: 'GET'
  };
  
  return axios(config);
}

exports.getLatestPrice = getLatestPrice;

I get the following error:

Access to XMLHttpRequest at 'https://api.kraken.com/0/public/Trades?pair=ETHUSDT&since=1656322000' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

My code in vanilla js file

const axios = require('axios');

const url = "https://api.kraken.com/0/public/Trades?pair=ETHUSDT&since=1656322000";


const config = {
  url: url,
  method: "GET"
};

axios(config).then(res => {
  console.log(res.data);
}).catch(err => {
  console.log(err);
});

Here I am getting the correct response. The postman request to the same is also working.

(I am not controlling the API backend)

about 4 years ago · Juan Pablo Isaza
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!