Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

How to fetch data from an api async and await

async function fetchData() {
    try {
      const result = await axios.get("https://randomuser.me/api/")
      console.log(result.data));
    } catch (error) {
      console.error(error);
    }
  }
Comment

fetch get data async

async function fetchMovies() {
  const response = await fetch('/movies');
  // waits until the request completes...
  console.log(response);
}
Comment

js undici fetch data async

import { fetch } from "undici";

const data = {
  async *[Symbol.asyncIterator]() {
    yield "hello";
    yield "world";
  },
};

(async () => {
  await fetch("https://example.com", { body: data, method: 'POST' });
})();
Comment

PREVIOUS NEXT
Code Example
Javascript :: setImmediate() nodejs 
Javascript :: what is react 
Javascript :: using cors as middleware in js 
Javascript :: convert int to string in angular 
Javascript :: how to send the mail using node with template 
Javascript :: Ternary Operator react 3 Conditions 
Javascript :: nuxt store watch 
Javascript :: Update select2 after removing an element 
Javascript :: how to import pdfmake/build/pdfmake.min in react 
Javascript :: upload image to server next js 
Javascript :: electron js execute command 
Javascript :: first letter string uppercase javascript 
Javascript :: insert multiple Row in SQL database with NodeJS 
Javascript :: Uncaught TypeError: Data.filter is not a function 
Javascript :: react native docs 
Javascript :: DevDependencies and dependencies syntax in Node package.json 
Javascript :: legend on click use default chartjs 
Javascript :: detect keyboard open or close in react js 
Javascript :: js clear map 
Javascript :: dynamic regex javascript 
Javascript :: get size of array in bytes javascript 
Javascript :: filter array 
Javascript :: how to build jquery post data 
Javascript :: add parameter submit form javascript 
Javascript :: convert object to url javascript 
Javascript :: js reduce method 
Javascript :: javascript find and update element from array 
Javascript :: The slice JavaScript string method 
Javascript :: javascript escape single quote 
Javascript :: regex char or char 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =