new mw.ForeignRest(url, foreignActionApi, optionsopt)
#
Create an object like mw.Rest
, but automatically handling everything required to communicate
with another MediaWiki wiki via cross-origin requests (CORS).
The foreign wiki must be configured to accept requests from the current wiki. See https://www.mediawiki.org/wiki/Manual:$wgCrossSiteAJAXdomains for details.
var api = new mw.ForeignRest( 'https://commons.wikimedia.org/w/rest.php' );
api.get( '/page/Main_Page/html' )
.done( function ( data ) {
console.log( data );
} );
Authentication-related MediaWiki extensions may extend this class to ensure that the user authenticated on the current wiki will be automatically authenticated on the foreign one. These extension modules should be registered using the ResourceLoaderForeignApiModules hook. See CentralAuth for a practical example. The general pattern to extend and override the name is:
function MyForeignRest() {};
OO.inheritClass( MyForeignRest, mw.ForeignRest );
mw.ForeignRest = MyForeignRest;
Parameters:
Name | Type | Attributes | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
url |
string | URL pointing to another wiki's |
|||||||||||
foreignActionApi |
mw.ForeignApi | ||||||||||||
options |
Object |
<optional> |
See Properties
|
- Since:
- 1.36
- Source:
Create an object like mw.Rest
, but automatically handling everything required to communicate
with another MediaWiki wiki via cross-origin requests (CORS).
Extends
Methods
abort()
#
Abort all unfinished requests issued by this Api object.
- Inherited From:
- Source:
ajax(path, ajaxOptionsopt) → {jQuery.Promise}
#
Perform the API call.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
path |
string | ||
ajaxOptions |
Object |
<optional> |
- Inherited From:
- Source:
Returns:
Done: API response data and the jqXHR object. Fail: Error code
- Type
- jQuery.Promise
delete(path, body, headersopt) → {jQuery.Promise}
#
Perform REST API DELETE request.
Note: only sending application/json
is currently supported.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
path |
string | ||
body |
Object | ||
headers |
Object |
<optional> |
- Inherited From:
- Source:
Returns:
- Type
- jQuery.Promise
get(path, query, headersopt) → {jQuery.Promise}
#
Perform REST API get request.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
path |
string | ||
query |
Object | ||
headers |
Object |
<optional> |
- Inherited From:
- Source:
Returns:
- Type
- jQuery.Promise
post(path, bodyopt, headersopt) → {jQuery.Promise}
#
Perform REST API post request.
Note: only sending application/json is currently supported.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
path |
string | ||
body |
Object |
<optional> |
|
headers |
Object |
<optional> |
- Inherited From:
- Source:
Returns:
- Type
- jQuery.Promise
put(path, body, headersopt) → {jQuery.Promise}
#
Perform REST API PUT request.
Note: only sending application/json
is currently supported.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
path |
string | ||
body |
Object | ||
headers |
Object |
<optional> |
- Inherited From:
- Source:
Returns:
- Type
- jQuery.Promise