Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A JSON-P server in Sinatra

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 README.rdoc
Octocat-spinner-32 config.ru
Octocat-spinner-32 config.yml
Octocat-spinner-32 deploy.rb
Octocat-spinner-32 freddy.god
Octocat-spinner-32 freddy.rb
README.rdoc

Freddy is a JSON Slasher!

Freddy is a standalone JSONP proxy written in Sinatra. Running Freddy lets you integrate JSON APIs that do not provide their own JSONP facilities in pages running on your own domain. For more information on JSONP or Sinatra follow the lnks at the bottom of this README.

Once you have deployed Freddy on your own server, access it like this:

freddy.mydomain.com?url=<uri-encoded json-returning url>&callback=<name of my callback function>

The response will look like this:

myCallback({'foo' : 'bar'})

Where myCallback is the value you provided for the 'callback' param and {'foo' : 'bar'} is the json returned by GETting the url you provided to the 'url' param.

If you do not provide both of the paramters or if the url given cannot be accessed, Freddy will return an error response in the following format:

myCallback({'error' : '<description of error>'})

Note: Freddy just straight up GETs the url and spits back the result. So, if the result is an HD rip of Berlin Alexanderplatz, then your server will (un-)happily start pulling that down. Freddy implements a timeout on getting the JSON of 15 seconds. If requesting your JSON takes longer than that, Freddy will return an error message in the format described above.

There is no security. If you run this, anyone who knows about your Freddy URL will be able to access it for their arbitrary use. Deploy with caution.

NB.: This repo comes with some basic scripts for running Freddy under Thin via Rack and for monitoring it with God. If you want to use them, you'll need to edit some of the values to point at your copies of files. It should be pretty self-explanatory if you're familiar with Thin and God (if not, see the links below).

JSONP:

en.wikipedia.org/wiki/JSON#JSONP

remysharp.com/2007/10/08/what-is-jsonp/

ajaxian.com/archives/jsonp-json-with-padding

Sinatra:

sinatra.github.com

Thin:

code.macournoyer.com/thin/

God:

github.com/mojombo/god/tree/master

Something went wrong with that request. Please try again.