Skip to main content
Send Web Request

How to Make an HTTP Request with JavaScript

JavaScript uses the Fetch API for HTTP requests. It's built into modern browsers and Node.js (18+), and returns Promises.

GET request example

Making a GET request to fetch data with custom headers:

const response = await fetch("https://api.example.com/users", {
  method: "GET",
  headers: {
    "Accept": "application/json",
    "Authorization": "Bearer YOUR_TOKEN"
  }
});
const data = await response.json();

POST request example

Making a POST request to send JSON data:

const response = await fetch("https://api.example.com/users", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ name: "John", email: "john@example.com" })
});
const data = await response.json();

Other libraries you can try