Home / Attachments / Untitled Snippet
Duplicate Snippet

Embed Snippet on Your Site

Untitled Snippet

Mwanaidi Masoud PRO
<10
Code Preview
js
// Define the API URL
const apiUrl = 'https://api.example.com/data';
// Make a GET request
fetch(apiUrl)
  .then(response => {
    if (!response.ok) {
      throw new Error('Network response was not ok');
    }
    return response.json();
  })
  .then(data => {
    console.log(data);
  })
  .catch(error => {
    console.error('Error:', error);
  });

Comments

Add a Comment