forked from wikimedia/mediawiki-api-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_info.js
33 lines (26 loc) · 840 Bytes
/
get_info.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//This file is autogenerated. See modules.json and autogenerator.py for details
/*
get_info.js
MediaWiki API Demos
Demo of `Info` module: Send a GET request to display information about a page.
MIT License
*/
var url = "https://en.wikipedia.org/w/api.php";
var params = {
action: "query",
format: "json",
titles: "Albert Einstein",
prop: "info",
inprop: "url|talkid"
};
url = url + "?origin=*";
Object.keys(params).forEach(function(key){url += "&" + key + "=" + params[key];});
fetch(url)
.then(function(response){return response.json();})
.then(function(response) {
var pages = response.query.pages;
for (var p in pages) {
console.log(pages[p].title + " has " + pages[p].length + " bytes.");
}
})
.catch(function(error){console.log(error);});