Advanced Usage

Grape with Padrino

Create your new project. It can be a regular one:

$ padrino g project grappe

Or a lean one if you don't want any Sinatra apps in it:

$ padrino g project grappe --lean

Go to the new grappe folder and add gem 'grape' to Gemfile. Then install the required gems:

$ bundle

Create file api/api.rb and put your Grape code there:

module Grappe
  class API < Grape::API
    get :hello do
      { hello: 'grape' }

    get 'status' do
      cookies[:status_count] ||= 0
      cookies[:status_count] = cookies[:status_count].to_i + 1
      { status_count: cookies[:status_count] }

Go to file config/apps.rb and add to the end of it:

Padrino.mount('API', :app_file => Padrino.root('api/api.rb'), :app_class => 'Grappe::API').to('/master')

Now you can run rackup from your gapp folder and visit or

<?xml version="1.0" encoding="UTF-8"?>

<?xml version="1.0" encoding="UTF-8"?>
  <status-count type="integer">1</status-count>

You can find the code on Github.

last updated: 2022-02-22

comments powered by Disqus