Advertisement
dereksir

Untitled

Apr 25th, 2024
653
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // import the required libraries
  2. import axios from 'axios';
  3. import got from 'got';
  4.  
  5. // define the target URL
  6. const url = "https://httpbin.io/ip";
  7.  
  8. // got
  9. console.time("Got");
  10. (async () => {
  11.     try {
  12.         const response = await got(url);
  13.         console.log(response.body);
  14.         console.timeEnd("Got");
  15.     } catch (error) {
  16.         console.log(error.response.body);
  17.     }
  18. })();
  19.  
  20. // axios
  21. console.time("Axios");
  22. axios.get(url)
  23.     .then(response => {
  24.         console.log(response.data);
  25.         console.timeEnd("Axios");
  26.     })
  27.     .catch(error => {
  28.         console.log(error.response.data);
  29.     });
  30.  
  31. // fetch
  32. console.time('Fetch');
  33.  
  34. fetch(url)
  35.   .then((response) => response.json())
  36.   .then((data) => {
  37.     console.log(data);
  38.     console.timeEnd('Fetch');
  39.   });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement