11 | | All API calls allow the JSONP 'callback' parameter to be specified in the request and this wraps the JSON response. |
| 11 | All API calls allow the JSONP 'callback' parameter to be specified in the request and this wraps the JSON response. See suggested patch to rest.py by Donovan Hide: |
| 12 | |
| 13 | http://knowledgeforge.net/ckan/trac/attachment/ticket/336/resource.patch |
| 14 | |
| 15 | == Test == |
| 16 | |
| 17 | import re |
| 18 | import unittest |
| 19 | |
| 20 | def test_jsonp_callback(): |
| 21 | response = self.app.get('/api/search/resource/?url=http://www.scraperwiki.com&callback=jsoncallback') |
| 22 | match = re.match('jsoncallback\(.*\);',response) |
| 23 | self.assertTrue(match) |
| 24 | |
| 25 | response = self.app.get('/api/search/resource/?url=http://www.scraperwiki.com') |
| 26 | match = re.match('jsoncallback\(.*\);',response) |
| 27 | self.assertFalse(match) |
| 28 | |
| 29 | I think the point needs to be made that JSONP only works for GET |
| 30 | requests and not POST/PUT/DELETE, so there needs to be a check |
| 31 | for that in the _finish_ok method. |
| 32 | |
| 33 | (thanks to Donovan Hide for test) |