JSONP output helper for Sinatra
Sinatra framework is an excellent start for anybody who wants to make own backend service. If you are using jQuery on frontend and it’s jQuery.getJSON() method you can do crossdomain requests to your Sinatra application with JSONP callbacks. To be able to do this your service should return JSONP data. I tried to make things straightforward and wrote simple Sinatra extension that outputs proper JSONP response.
The helper is pretty simple, just pass the object to jsonp method and it will return proper JSONP response if any callbacks were detected in request, instead it will output the plain JSON. Also if you want to define your own custom callback name you can pass the second string param with your preferred callback name.
Installation
Usage
Gemfile
Classic
Modular