Reputation: 16780
An API feature has been added to WAMS where I can define custom scripts. This seems to deprecate the previous practice of creating a script table. However, I couldn't find any description about how I can use it.
Which clients make this feature accessible? Can it be used from iOS or Javascript?
Upvotes: 5
Views: 6573
Reputation: 87218
And a couple more posts on this topic: http://blogs.msdn.com/b/carlosfigueira/archive/2013/06/14/custom-apis-in-azure-mobile-services.aspx (server side) and http://blogs.msdn.com/b/carlosfigueira/archive/2013/06/19/custom-api-in-azure-mobile-services-client-sdks.aspx (client side).
Also, since you tagged your question with ios, here's the code you'd use to call the API using an instance of the MSClient
class:
If your API only deals with (receives / returns) JSON data:
MSClient *client = [MSClient clientWithApplicationURLString:@"https://your-service.azure-mobile.net"
applicationKey:@"your-application-key"];
[client invokeApi:@"calculator/add"
body:nil
HTTPMethod:@"GET"
parameters:@{@"x":@7, @"y":@8} // sent as query-string parameters
headers:nil
completion:^(id result, NSURLResponse *response, NSError *error) {
NSLog(@"Result: %@", result);
}];
Or with a request body (POST):
[client invokeApi:@"calculator/sub"
body:@{@"x":@7, @"y":@8} // serialized as JSON in the request body
HTTPMethod:@"POST"
parameters:nil
headers:nil
completion:^(id result, NSHTTPURLResponse *response, NSError *error) {
NSLog(@"Result: %@", result);
}];
If your API deals with non-JSON data, you can use the other selector which takes / returns a NSData
object:
NSData *image = [self loadImageFromSomePlace];
[client invokeApi:@"processImage"
data:image
HTTPMethod:@"POST"
parameters:nil
headers:nil
completion:^(NSData *result, NSHTTPURLResponse *response, NSError *error) {
NSLog(@"Result: %@", result);
}];
Upvotes: 6
Reputation: 1250
i found this one help too:
http://www.windowsazure.com/en-us/develop/mobile/tutorials/create-pull-notifications-dotnet
basically you can access your custom API using this end-point format:
https://service_name.azure-mobile.net/api/api_name
put this on your script:
exports.get = function(request, response) {
response.send(200, "Hello World");
};
and set your API permission on GET to allow everyone, then you can use browser or fiddler to test your API by visiting the end-point:
https://service_name.azure-mobile.net/api/api_name
if you didn't change your permission, you have to put header code as below on your request:
GET https://service_name.azure-mobile.net/api/test HTTP/1.1
User-Agent: Fiddler
Content-type: application/json
X-ZUMO-APPLICATION: your-manage-key-here
Upvotes: 5
Reputation: 7860
this might help: What’s new in Windows Azure Mobile Service : Api Script
Upvotes: 5