DEV Community

SATHISHKUMAR R
SATHISHKUMAR R

Posted on

What is fetch() in JavaScript?

fetch() is a built-in JavaScript function used to send HTTP requests and get data from a server/API.

It is commonly used to connect a frontend application with a backend or external API.

Flow Chart:

JavaScript
↓
fetch()
↓
API / Server
↓
Response
↓
response.json()
↓
JavaScript Data

Example:

fetch("https://jsonplaceholder.typicode.com/users")
.then(response => response.json())
.then(data => {
console.log(data);
})
.catch(error => {
console.log(error);
});

Top comments (0)