API:REST API/Reference/Sample code:Get page history counts

curl

edit
# Get the number of edits to a page between revisions 384955912 and 406217369
$ curl "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/history/counts/edits?from=384955912&to=406217369"


Python

edit
# Get the number of edits to a page between revisions 384955912 and 406217369
import requests

url = 'https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/history/counts/edits'
headers = {
    'User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'
}
params = {
    'from': '384955912',
    'to': '406217369'
}

response = requests.get(url, headers=headers, params=params)
data = response.json()

print(data)


<?php
/*
Get the number of edits to a page between revisions 384955912 and 406217369
*/
$url = "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/history/counts/edits";
$params = [ "from" => "384955912", "to" => "406217369" ];
$url = $url . "?" . http_build_query( $params );

$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_USERAGENT, "MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)" );
$output = curl_exec( $ch );
curl_close( $ch );

echo($output);
?>


JavaScript

edit
/*  
    Get the number of edits to a page between revisions 384955912 and 406217369
*/
async function doFetch() {
  let url = "https://en.wikipedia.org/w/rest.php/v1/page/Jupiter/history/counts/edits";
  let headers = {'Api-User-Agent': 'MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)'}
  let params = {
    'from': '384955912',
    'to': '406217369'
  };
  let query = Object.keys(params)
             .map(k => k + '=' + encodeURIComponent(params[k]))
             .join('&');
  url = url + '?' + query;

  const rsp = await fetch(url, headers);
  const data = await rsp.json();
  return data;
}

async function fetchAsync()
{
  try {
    let result = await doFetch();
    console.log(result);
  } catch( err ) {
    console.error( err.message );
  }
}

fetchAsync();