Skip to main content
D
JavaScript
JavaScript Fetch API

JavaScript Fetch API

JavaScript Fetch API requests data from a web server.

Read Time
5 min read
Difficulty
Beginner
Last Updated
Jun 15, 2026
Version
v1.0.0

Introduction

JavaScript uses the Fetch API to ask a server for data behind the scenes. Without reloading the page, developers can pull in fresh weather data, stock prices, or new social media posts. The Fetch API relies entirely on Promises.

Example

Example
1/* this fetches data */
2fetch("https://api.example.com/data")
3  .then(response => response.json())
4  .then(data => console.log(data));

Key Points

  • The `fetch()` function starts the network request.
  • It returns a Promise that resolves to a Response object.
  • You must convert the response to JSON or text.
  • Fetch replaces the older `XMLHttpRequest` method.

Up Next

Continue your journey with the next topic.

Go to JS JSON