Using Async/Await

For cleaner asynchronous code, you can use async/await:

async function fetchData() {
  try {
    const response = await axios.get('https://jsonplaceholder.typicode.com/posts');
    console.log('Data:', response.data);
    console.log('Status:', response.status);
  } catch (error) {
    console.error('Error:', error);
  }
}

fetchData();

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *