Web Services JSONP support

JSONP (JSON with Padding) lets you achieve cross-domain data fetching from any Javascript function running inside a browser.

JSONP requires a little assistance from both the server and the client inorder for it to work. JSONP works by wrapping the returning JSON packet in () and prepending a name to make it into a Javascript document.

The majority of Javascript libraries support JSON from their native core. JQuery supports it using $.getJSON method, which simply asks that you append the URI parameter "callback=?" to the end of the remote URL and it will do all the marshalling of data for you.

Enabling JSONP in OpenBD

Before you do that, you have to tell OpenBD that this is a JSONP request and allow it the opportunity to post-process the packet for you. You do this using the existing __BDRETURNFORMAT parameter flag and setting it to "jsonp". OpenBD will look for the "callback" parameter and the take the necessary action for you accordingly.

An example of this in action from standard JQuery:

    // do something with the 'json' object

The advantage of this, is that you do not need to modify your existing CFC's inorder for them to be consumed using JSONP methods. There is also huge memory and performance gains to be had, letting the core engine do all the heavy lifting instead of the existing workarounds written in CFML.

Controlling incoming data

OpenBD has enabled a number of flags that the remote REST client can use to help format the data coming back from the server without having to touch your CFC.

  • method=myFunction
    This determines which function of the CFC will be called (required)
  • __BDRETURNFORMAT=wddx|plain|json|jsonp
    This determines how the function will format its return content.
    If this parameter exists, any error the CFC throws will be surpressed. This stops the full error stack page to be sent to the remote caller.
  • __BDQUERYFORMAT=column|row
    If the CFC is returning back a CFML Query object, then this controls how the data is represented, either as an array of rows, or array of columns.

Through the use of these (case insensitive) flags you can control how you wish the data to be presented by the client instead of having to modify any server-side code, making it easier for you to offer greater flexibility to your web services clients.