Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

JSONP

JSON (Json with Padding) complements in the existing capability of Enterprise Tester API methods to return JSON. I provides a method to request data from the server where CORS is not a viable alternative.

In a JSONP request, the contents of the response is wrapped in a javascript function call, which allows you to fetch it with a script tag, and the have to response automatically invoke the callback once loaded, to process the response body - let's take a look at an example:

To make a JSONP request you pass an additional query parameter as part of the url with the name "callback", the value of which is the name of the callback function to invoke:

Example

If we make a request as follows:

No Format
GET http://localhost/EnterpriseTester/api/groups?callback=processResponse

Then we can see in the response, that it's wrapped in a call to the function processResponse:

Code Block
languagenone
processResponse({
  "Items": [
    {
      "Id": "2192ce56-971d-4b19-9df7-a0770041f1cf",
      "Name": "Viewer",
      "Description": "Viewer",
      "Expands": [
        "Users"
      ],
      "Self": "http://localhost/EnterpriseTester/api/group/2192ce56-971d-4b19-9df7-a0770041f1cf",
      "Links": [...]
    },
    ...
  ],  
  "Self": "http://localhost/EnterpriseTester/api/groups?callback=process"
})

Limitations

JSONP requests are only support for GET HTTP methods.