If you try to access data in a different domain from a client side app, you’ll often get an error about CORS (cross origin resource sharing). I’ve dealt with this topic before in Cross Origin Resource sharing (CORS), where there is some code that does that from a client. However this only works if the server you are talking to supports CORS.

What’s it all about

Before CORS was widely implemented, JSONP was pretty much the only way you could get data stored on a different domain into your client side APP, unless you happened to have a server to use, but that relied on the app you were querying supporting JSONP. For those that didn’t, there are a many examples of PHP proxy scripts, including on this site, to be able to take data from one site, wrap it in JSONP and send it to the client requestor. Nowadays it’s less common to have a handy server, as we use more cloud based solutions.

Apps Script as a proxy

Since Apps Script runs on a server, sites are generally quite happy to serve up JSON data to it, so this means that you can get away from needing PHP and a server as a proxy, since you can just use Apps Script. Here’s a simple script you can publish as a webapp to do this for you. It’s also on github.

To use

Once your webapp is published, you can invoke it with this url from your client app.

if jQuery, then you can use

The response

Your callback will return this object

And that’s it.

Since I moved off my own server to Cloud Storage, I’ve had to migrate from the PHP proxy I was using before. An example of it can be seen in Flight data from Fusion which takes a whole heap of data from Google Fusion, Google Sheets and a few other places to create a visualization of flights and airline on time performance using d3.js

For more like this, see Google Apps Scripts Snippets

Why not join our forum, follow the blog or follow me on Twitter to ensure you get updates when they are available.