How To Make An HTTP Request in Javascript, All Methods

Mark Caggiano
5 min readMay 9, 2023

In JavaScript, you can make HTTP requests using the XMLHttpRequest object or the newer fetch API. I'll provide examples for both approaches.

Using XMLHttpRequest

var xhr = new XMLHttpRequest();
xhr.open("GET", "https://api.example.com/data", true);
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status ===…

--

--