FatFractal customer forums



Author Topic: Can a server extension return something other than a custom object?  (Read 1638 times)

Andre

  • Newbie
  • *
  • Posts: 13
    • View Profile
I'd rather not create a custom object just to get a number back. Can a server extension return something like NSNumber or just a value or is there another way to do this?

gkc

  • Administrator
  • *****
  • Posts: 375
    • View Profile
You can; but the easiest thing to do is to return an object like this
Code: [Select]
ff.response().result = {a: 12345};
On the client side this will be unmarshalled to (iOS) NSDictionary or (Android) Map

If you want to return the minimum data possible then you can do something like this:
server-side
Code: [Select]
exports.testReturnJustNumber = function() {
    ff.response().mimeType = "text/plain";
    ff.response().result = 12345;
};
Client-side (iOS)
Code: [Select]
    NSData * rawResponse = [[[[ff newReadRequest] prepareGetFromExtension:@"/ff/ext/testReturnJustNumber"] executeSync] rawResponseData];
    NSString *foo = [[NSString alloc] initWithData:rawResponseData encoding:NSUTF8StringEncoding];
Client-side (Android)
Code: [Select]
        final byte[] rawResponse = ff.newReadRequest().prepareGetFromUri("/ff/ext/testReturnJustNumber").execute().getRawResponse();
        String response = new String(rawResponse);

Andre

  • Newbie
  • *
  • Posts: 13
    • View Profile
Works. Wasn't sure what types the client would accept.

 

Copyright © FatFractal customer forums