mw.Rest

Interact with the REST API. mw.Rest is a client library for the REST API. An mw.Rest object represents the REST API of a MediaWiki site. For the action API, see mw.Api.

Example

var api = new mw.Rest();
api.get( '/v1/page/Main_Page/html' )
.then( function ( data ) {
    console.log( data );
} );

api.post( '/v1/page/Main_Page', {
     token: 'anon_token',
     source: 'Lörem Ipsüm',
     comment: 'tästing',
     title: 'My_Page'
}, {
    'authorization': 'token'
} )
.then( function ( data ) {
    console.log( data );
} );

Constructor

new mw.Rest(options) #

Create an instance of mw.Rest.

Parameters:

Name Type Attributes Description
options mw.Rest.Options optional

See mw.Rest.Options

Source:

Methods

abort() #

Abort all unfinished requests issued by this Api object.

Source:
Abort all unfinished requests issued by this Api object.

ajax(path, ajaxOptions) → {jQuery.Promise} #

Perform the API call.

Parameters:

Name Type Attributes Description
path string
ajaxOptions Object optional
Source:

Returns:

Done: API response data and the jqXHR object. Fail: Error code

Type
jQuery.Promise
Perform the API call.

delete(path, body, headers) → {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
Source:

Returns:

Type
jQuery.Promise
Perform REST API DELETE request.

get(path, query, headers) → {jQuery.Promise} #

Perform REST API get request.

Parameters:

Name Type Attributes Description
path string
query Object
headers Object optional
Source:

Returns:

Type
jQuery.Promise
Perform REST API get request.

post(path, body, headers) → {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
Source:

Returns:

Type
jQuery.Promise
Perform REST API post request.

put(path, body, headers) → {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
Source:

Returns:

Type
jQuery.Promise
Perform REST API PUT request.

Type Definitions

Options #

Type:

Properties:

Name Type Attributes Default Description
ajax Object optional
{ url: mw.util.wikiScript( 'rest' ), timeout: 30 * 1000 }

Default options for ajax() calls. Can be overridden by passing options to the mw.Rest constructor.

Source: