Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // import the required libraries
- import axios from 'axios';
- import got from 'got';
- // define the target URL
- const url = "https://httpbin.io/ip";
- // got
- console.time("Got");
- (async () => {
- try {
- const response = await got(url);
- console.log(response.body);
- console.timeEnd("Got");
- } catch (error) {
- console.log(error.response.body);
- }
- })();
- // axios
- console.time("Axios");
- axios.get(url)
- .then(response => {
- console.log(response.data);
- console.timeEnd("Axios");
- })
- .catch(error => {
- console.log(error.response.data);
- });
- // fetch
- console.time('Fetch');
- fetch(url)
- .then((response) => response.json())
- .then((data) => {
- console.log(data);
- console.timeEnd('Fetch');
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement