User:Gauransh Dingwani/API-Demo.js

mw.loader.using( 'mw.Api' ).then( function {	// Call to the function that uses mw.Api	var api = new mw.Api;	api.get( { action: 'query', prop: 'pageviews', titles: [ mw.config.get( 'wgPageName' ) ] } ).done( function ( data ) { const object = data.query.pages[ mw.config.get( 'wgArticleId' ) ].pageviews; var sum = 0; for ( const property in object ) { sum += object[ property ]; }		var label = ' ( ' + sum + ' views in last 2 months )'; $( '#firstHeading' ).append( label ); } ); } );