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

188
Views
How to make synchronous HTTP GET request in JavaScript with axios?

I'm trying to do something like this:

const axios = require('axios');
function load() {
  const response = axios.get('https://...');
  return response.data;
}

I can't make my function async. I need it to be declared exactly this way and return the data loaded from the URL via GET request.

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

0

Well you can try using XMLhttprequest:

const XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;

function syncRequest(url) {
  var xhr = new XMLHttpRequest();
  xhr.open("GET", url, false);
  xhr.send(null);
  return xhr.responseText;
}

(() => {
  const res = syncRequest("https://api.github.com/users/octocat");
})();

It will block until it receives an response

You will need to install the XMLHttprequest package:

https://www.npmjs.com/package/xmlhttprequest

about 4 years ago · Juan Pablo Isaza Report

0

suggestion: using async await

const axios = require('axios');

async function load() {
  const response = await axios.get('https://...');
  ...
}
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!