Advanced Usage
3rd Party Plugins
Padrino is a modular framework. As such, you can leverage other libraries such as Sinatra libraries which complement Padrino quite well.
Rendering JSON with sinatra-contrib
First you must reference sinatra-contrib in your Gemfile:
# Gemfile
source 'https://rubygems.org'
# Project requirements
gem 'rake'
# Component requirements
gem 'haml'
# Test requirements
# Padrino Stable Gem
gem 'padrino', '~> 0.16.0'
# Or Padrino Edge
# gem 'padrino', github: 'padrino/padrino-framework'
# Or Individual Gems
# %w(core support gen helpers cache mailer admin).each do |g|
# gem 'padrino-' + g, '~> 0.16.0'
# ends
gem 'sinatra-contrib'
You may use the #json method after you have registered the sinatra helper:
module MyJsonApp
class App < Padrino::Application
register Padrino::Mailer
register Padrino::Helpers
helpers Sinatra::JSON
enable :sessions
get '/' do
hash = { foo: 'bar' }
json hash
end
end
end
last updated: 2025-12-02
comments powered by Disqus