API:Documentation template
![]() | This page is part of the MediaWiki Action API documentation. |
MediaWiki version: | ≥ 1.23 |
API documentation
To embed the documentation of an API module, use the template below. Remember to replace "module name" with the name of an actual module. All main modules are here.
![]() | The following documentation is the output of Special: |
Example
GET request
Description of script
Response
{
"batchcomplete":""
}
Sample code
Create a sub page of this page to host the Python, PHP and JavaScript sample code, then transclude that page into this page. Name the page Sample code n
, where n=1,2,3...n depending on the number of examples you have. Look at API:Tags and API:Tags/Sample_code_1 for reference.
Python
#!/usr/bin/python3
"""
hello.py
MediaWiki Action API Code Samples
Demo of `...` module
MIT license
"""
import requests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
PARAMS = {
'action':"query",
'format':"json"
}
R = S.get(url=URL, params=PARAMS)
DATA = R.json()
print(DATA)
PHP
<?php
/*
hello.php
MediaWiki API Demos
Demo of `...` module
MIT License
*/
$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
"action" => "query",
"format" => "json"
];
$url = $endPoint . "?" . http_build_query( $params );
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$output = curl_exec( $ch );
curl_close( $ch );
$result = json_decode( $output, true );
echo( $result );
JavaScript
/*
hello.js
MediaWiki API Demos
Demo of `...` module
MIT License
*/
var url = "https://en.wikipedia.org/w/api.php";
var params = {
action: "query",
format: "json"
};
url = url + "?origin=*";
Object.keys(params).forEach(function(key){url += "&" + key + "=" + params[key];});
fetch(url)
.then(function(response){return response.json();})
.then(function(response) {
console.log(response);
})
.catch(function(error){console.log(error);});
MediaWiki JS
/*
hello.js
MediaWiki API Demos
Demo of `...` module
MIT License
*/
var params = {
action: 'query',
format: 'json'
},
api = new mw.Api();
api.get( params ).done( function ( data ) {
console.log( data );
} );
Demo app(s)
- Add a link to the demo app. Embed an image of the demo if applicable
Possible errors
Code | Info |
---|---|
Parameter history
- v1.x: Introduced
parameter_1
,parameter_2
- v0.x: Deprecated
parameter_3
Additional notes
See also
- Add link to documentation of related modules