SALES: 1-800-867-1380

MobileServiceClient.invokeApi function

Updated: June 20, 2013

Gets a reference to a table and its data operations.

mobileServiceClient.invokeApi(apiName, options);

apiName
Type: string

The name of the custom API that is being invoked.

options
Type: object

A JSON object that directs the client on how to access the custom API, which has the following format:

{
    body: request_body,
    method: request_method,
    parameters: parameters, 
    headers: request_headers
}
  • request_body – the body of the HTTP request message. The format of the supplied body must match the format expected by the custom API.

  • request_method – a supported HTTP method, which can be get, post, patch, update, or delete. The default is post. The request is sent by using the HTTP method specified.

  • parameters – an optional JSON object that specifies one or more named parameters as fields.

  • request_headers – an optional JSON object that specifies one or more HTTP headers to be added to the request.

Type: A Promise object that returns an XMLHttpRequest object when it completes.

Call the done method on the returned Promise object to access the response and handle any errors.

The following example shows how to call a custom API named completeAll that returns an integer value. For more information, see Call a custom API from the client.

var completeAllTodoItems = function () {
    var okCommand = new Windows.UI.Popups.UICommand("OK");

    // Asynchronously call the custom API using the POST method. 
    mobileService.invokeApi("completeall", {
        body: null,
        method: "post"
    }).done(function (results) {
        var message = results.result.count + " item(s) marked as complete.";
        var dialog = new Windows.UI.Popups.MessageDialog(message);
        dialog.commands.append(okCommand);
        dialog.showAsync().done(function () {
            refreshTodoItems();
        });
    }, function (error) {
        var dialog = new Windows.UI.Popups
            .MessageDialog(error.message);
        dialog.commands.append(okCommand);
        dialog.showAsync().done();
    });
};

A JSON object expression of the response body received from the custom API is accessed from the result property of the XMLHttpRequest object supplied to the promise. For more information, see Call a custom API from the client.

 

Namespace

WindowsAzure.MobileServices

Library

MobileServices.js

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft