Nearby lessons
20 of 22JavaScript: fetch() API
📌 What is Fetch API?
The fetch() API is used to make HTTP requests in JavaScript. It returns a Promise that resolves to the response of the request. It's commonly used to get data from APIs or load resources like text or JSON.
1️⃣ Fetch Text File using then()
Fetch a local file (like readme.txt) and read its content using response.text().
Example02
2️⃣ Short Version using Arrow Functions
A more concise version using arrow functions and implicit returns.
Example03
3️⃣ Fetch JSON Data from API
Use fetch() to get JSON data from a REST API and log it in the console.
Example04
4️⃣ Display API Data on the Page
This example fetches user data from an API and displays each user's name in the browser.
Example05
🧠 Test Your Knowledge
3 QuestionsProgress: 0 / 3