<file_sep>require 'sinatra'
require 'uri'
require 'net/http'

Sinatra.new do
  configure :production do
    require 'newrelic_rpm'
  end

  get '/' do
    if params[:uri] && params[:callback]
      handle_jsonp_request
    else
      handle_invalid_request
    end
  end

  def handle_jsonp_request
    json = Net::HTTP.get_response(URI.parse(params[:uri])).body
    content_type :json
    "#{params[:callback]}(#{json})"
  end

  def handle_invalid_request
    content_type :text
    "Usage: /?callback={insert callback name}&uri={insert JSON URI}"
  end
end.run!
<file_sep># Usage
There are two required query parameters:
- `uri`: the URI of the original JSON endpoint
- `callback`: that name of the JSONP callback function. Note: jQuery.ajax automatically adds one for you with `dataType: jsonp`.

# Example
http://jsonpfy.herokuapp.com/?callback=what&uri=http%3A%2F%2Fwww.reddit.com%2F.json
