fbpx

JSONP

You are here:
< Back

JSON (Json with Padding) complements in the existing capability of Enterprise Tester API methods to return JSON. It 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:

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:

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.

Tags: