dj-webmachine
dj-webmachine copied to clipboard
Add JSONP support
Having JSONP support should be great to use the API form other domains.
jsonp isn't really good for security (http://stackoverflow.com/questions/613962/is-jsonp-safe-to-use) .
Anyway which level of support do you want for this api ? Almost everything is here.
Thank you for the pointer. I thought about it : maybe using a middleware should do the trick. So, basically, we're searching for some querystring parameter, say "callback", and append it to the response. What do you think ?
I'm not sure you need something specific for that. You can just send a "callback(%s)" % json_response in the response I think. Would it works ?
Sure it will, but i will need to override each resource's to_json method, isn't it ? Which is not DRY :'(
hum I was thinking to have something like:
if "callback" in request.PARAMS:
resp = "%s(%s)" % (request.PARAMS['callback'], resp)
return resp
in your to_json function. The problem is that having a specific behaviour for json.
Maybe a better solution would be to pass a callback option to the json serializer. I will have a look on that.
Right now, i'm fine with the Middleware idea. I'll checkout it and see whether still relevant. Thanks for your feedback.