MobileServiceClient.invokeApi function
Gets a reference to a table and its data operations.
mobileServiceClient.invokeApi(apiName, options);
Parameters
apiName
Type: stringThe name of the custom API that is being invoked.
options
Type: objectA 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.
Return Value
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.
Example
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();
});
};
.NET Framework Equivalent
InvokeApiAsync
Remarks
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.
Requirements
Namespace |
WindowsAzure.MobileServices |
Library |
MobileServices.js |
See Also
Reference
Other Resources
Call a custom API from the client
How to use an HTML/JavaScript client for Azure Mobile Services