Fork me on GitHub


A Rack JSONP middleware


This is a customized implementation of a JSONP middleware.

The main difference with the rest of them is that this one will add JSONP support to any of your JSON calls but only when the extension name '.jsonp' is present.

Since 'callback' is a really generic parameter name if someone wants to get a JSONP response they must request it explicitly.

Btw, don't forget to give a try to J50Nπ (a pure JS JSONP helper), they make a lovely couple together :P


Roberto Decurnex (


If you are using Bundler you can easily add the following line to your Gemfile:

gem 'rack-jsonp-middleware'

Or you can just install it as a ruby gem by running:

$ gem install rack-jsonp-middleware


Rails 3

In your config/application.rb file add:

require 'rack/jsonp'

And, within the config block:

config.middleware.use Rack::JSONP

Here is an exelent example of this - Rails 3 Configuration Example

Thank you rwilcox!

Rails 2

Same as for Rails 3 but modifying the config/environment.rb file instead.

Rack Apps

In your file add the following lines:

  require 'rack/jsonp'
  use Rack::JSONP


You can download this project in either zip or tar formats.

You can also clone the project with Git by running:

$ git clone git://

How it works

Given that returns the following:


With the following Content-Type:


Then will return the following:


With the following Content-Type:


But will still returns the following:


With the following Content-Type:



Please report any issue or advise here at Github.