Ajax calls
This commit is contained in:
@@ -5,7 +5,10 @@
|
||||
[libs]
|
||||
|
||||
[lints]
|
||||
all=warn
|
||||
unsafe-getters-setters=off
|
||||
|
||||
[options]
|
||||
include_warnings=true
|
||||
|
||||
[strict]
|
||||
|
||||
Generated
+29
-4
@@ -332,6 +332,15 @@
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"axios": {
|
||||
"version": "0.18.0",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-0.18.0.tgz",
|
||||
"integrity": "sha1-MtU+SFHv3AoRmTts0AB4nXDAUQI=",
|
||||
"requires": {
|
||||
"follow-redirects": "1.4.1",
|
||||
"is-buffer": "1.1.6"
|
||||
}
|
||||
},
|
||||
"babel-cli": {
|
||||
"version": "6.26.0",
|
||||
"resolved": "https://registry.npmjs.org/babel-cli/-/babel-cli-6.26.0.tgz",
|
||||
@@ -1991,6 +2000,24 @@
|
||||
"yargs": "4.8.1"
|
||||
}
|
||||
},
|
||||
"follow-redirects": {
|
||||
"version": "1.4.1",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.4.1.tgz",
|
||||
"integrity": "sha512-uxYePVPogtya1ktGnAAXOacnbIuRMB4dkvqeNz2qTtTQsuzSfbDolV+wMMKxAmCx0bLgAKLbBOkjItMbbkR1vg==",
|
||||
"requires": {
|
||||
"debug": "3.1.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"debug": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
|
||||
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
|
||||
"requires": {
|
||||
"ms": "2.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"for-in": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz",
|
||||
@@ -3258,8 +3285,7 @@
|
||||
"is-buffer": {
|
||||
"version": "1.1.6",
|
||||
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz",
|
||||
"integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==",
|
||||
"dev": true
|
||||
"integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w=="
|
||||
},
|
||||
"is-builtin-module": {
|
||||
"version": "1.0.0",
|
||||
@@ -3725,8 +3751,7 @@
|
||||
"ms": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=",
|
||||
"dev": true
|
||||
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
|
||||
},
|
||||
"mute-stream": {
|
||||
"version": "0.0.7",
|
||||
|
||||
+6
-13
@@ -15,10 +15,7 @@
|
||||
"author": "Federico Kereki",
|
||||
"license": "ISC",
|
||||
"babel": {
|
||||
"presets": [
|
||||
"env",
|
||||
"flow"
|
||||
]
|
||||
"presets": ["env", "flow"]
|
||||
},
|
||||
"eslintConfig": {
|
||||
"parserOptions": {
|
||||
@@ -28,16 +25,11 @@
|
||||
"parser": "babel-eslint",
|
||||
"env": {
|
||||
"browser": true,
|
||||
"node": true
|
||||
"node": true,
|
||||
"es6": true
|
||||
},
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:flowtype/recommended"
|
||||
],
|
||||
"plugins": [
|
||||
"babel",
|
||||
"flowtype"
|
||||
],
|
||||
"extends": ["eslint:recommended", "plugin:flowtype/recommended"],
|
||||
"plugins": ["babel", "flowtype"],
|
||||
"rules": {
|
||||
"no-console": "off"
|
||||
}
|
||||
@@ -47,6 +39,7 @@
|
||||
"printWidth": 75
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^0.18.0",
|
||||
"fetch": "^1.1.0",
|
||||
"moment": "^2.21.0"
|
||||
},
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
const axios = require("axios");
|
||||
|
||||
const BASE_URL = "https://weather.com/en-IN/weather/today/l/";
|
||||
|
||||
const MONTEVIDEO_UY = "-34.90,-56.16";
|
||||
const LONDON_EN = "51.51,-0.13";
|
||||
const PUNE_IN = "18.52,73.86";
|
||||
|
||||
const get_weather = coords => axios.get(`${BASE_URL}${coords}`);
|
||||
|
||||
async function getMontevideo() {
|
||||
try {
|
||||
const montevideoData = await get_weather(MONTEVIDEO_UY);
|
||||
|
||||
console.log("Montevideo, with promises");
|
||||
console.log(`Montevideo: ${montevideoData.data.length} bytes`);
|
||||
} catch (error) {
|
||||
console.log(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function getLondonAndPuneInSeries() {
|
||||
try {
|
||||
const londonData = await get_weather(LONDON_EN);
|
||||
const puneData = await get_weather(PUNE_IN);
|
||||
|
||||
console.log("London and Pune, in series");
|
||||
console.log(`London: ${londonData.data.length} b`);
|
||||
console.log(`Pune: ${puneData.data.length} b`);
|
||||
} catch (error) {
|
||||
console.log(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function getCitiesInParallel() {
|
||||
try {
|
||||
const montevideoGet = get_weather(MONTEVIDEO_UY);
|
||||
const londonGet = get_weather(LONDON_EN);
|
||||
const puneGet = get_weather(PUNE_IN);
|
||||
|
||||
const [montevideoData, londonData, puneData] = await Promise.all([
|
||||
montevideoGet,
|
||||
londonGet,
|
||||
puneGet
|
||||
]);
|
||||
|
||||
console.log("All three cities in parallel, with async/await");
|
||||
console.log(`Montevideo: ${montevideoData.data.length} b`);
|
||||
console.log(`London: ${londonData.data.length} b`);
|
||||
console.log(`Pune: ${puneData.data.length} b`);
|
||||
} catch (error) {
|
||||
console.log(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
getMontevideo();
|
||||
getLondonAndPuneInSeries();
|
||||
getCitiesInParallel();
|
||||
@@ -0,0 +1,57 @@
|
||||
const axios = require("axios");
|
||||
|
||||
const BASE_URL = "https://weather.com/en-IN/weather/today/l/";
|
||||
|
||||
const MONTEVIDEO_UY = "-34.90,-56.16";
|
||||
const LONDON_EN = "51.51,-0.13";
|
||||
const PUNE_IN = "18.52,73.86";
|
||||
|
||||
const get_weather = coords => axios.get(`${BASE_URL}${coords}`);
|
||||
|
||||
function getMontevideo() {
|
||||
get_weather(MONTEVIDEO_UY)
|
||||
.then(result => {
|
||||
console.log("Montevideo, with promises");
|
||||
console.log(`Montevideo: ${result.data.length} bytes`);
|
||||
})
|
||||
.catch(error => console.log(error.message));
|
||||
}
|
||||
|
||||
function getLondonAndPuneInSeries() {
|
||||
get_weather(LONDON_EN)
|
||||
.then(londonData => {
|
||||
get_weather(PUNE_IN)
|
||||
.then(puneData => {
|
||||
console.log("London and Pune, in series");
|
||||
console.log(`London: ${londonData.data.length} b`);
|
||||
console.log(`Pune: ${puneData.data.length} b`);
|
||||
})
|
||||
.catch(error => {
|
||||
console.log("Error getting Pune...", error.message);
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
console.log("Error getting London...", error.message);
|
||||
});
|
||||
}
|
||||
|
||||
function getCitiesInParallel() {
|
||||
const montevideoGet = get_weather(MONTEVIDEO_UY);
|
||||
const londonGet = get_weather(LONDON_EN);
|
||||
const puneGet = get_weather(PUNE_IN);
|
||||
|
||||
Promise.all([montevideoGet, londonGet, puneGet])
|
||||
.then(([montevideoData, londonData, puneData]) => {
|
||||
console.log("All three cities in parallel, with promises");
|
||||
console.log(`Montevideo: ${montevideoData.data.length} b`);
|
||||
console.log(`London: ${londonData.data.length} b`);
|
||||
console.log(`Pune: ${puneData.data.length} b`);
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error.message);
|
||||
});
|
||||
}
|
||||
|
||||
getMontevideo();
|
||||
getLondonAndPuneInSeries();
|
||||
getCitiesInParallel();
|
||||
Reference in New Issue
Block a user