// GET Request: fetch('https://api.example.com/data') .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Failed to fetch data', error)); // POST Request: fetch('https://api.example.com/data', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({name: 'John', job: 'Developer'}) }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Failed to post data', error));