// framework · grape

Grape: REST APIs, done Ruby-style.

The framework of choice for Ruby-first API teams. Mount it in Rails, or run it standalone on a lean Puma. Deploys like any other Rack app.

Grape is a DSL for HTTP APIs — versioning, param validation, and entity presenters, without the ceremony of a full framework. This guide covers both deployment modes: mounted inside a Rails app and standalone Rack on Puma.
118 MB
min container size (standalone)
~3.8k
req/s on 1 vCPU (standalone)
6 ms
typical p50 latency
01 / 04

Standalone Rack: the lean path

For pure-API services, skip Rails. A Grape app on Puma is a ~120 MB container that boots in under 300 ms — ideal for Cloud Run, Fargate or Container Apps.
ruby
# config.ru require "grape" class API < Grape::API format :json version "v1", using: :path resource :ping do get { { pong: Time.now.utc.iso8601 } } end end run API
02 / 04

Mounted in Rails

For teams already running Rails, mount Grape at /api and share the same deploy pipeline. No infra changes — just add the gem and a route.
ruby
# config/routes.rb mount API => "/api"
03 / 04

Versioning belongs in the URL

Grape supports header- and param-based versioning, but URL versioning (/v1/…) is the only kind CDNs and API gateways cache correctly. Pick it and never look back.
04 / 04

Entities, not to_json

Use Grape::Entity (or grape-swagger for OpenAPI) to lock down response shapes. Model.to_json leaks fields the day someone adds a column — an audit-log waiting to happen.

Gotchas we learned the hard way

  • !Grape's built-in logger writes to $stdout by default in newer versions — good. On older versions (<1.6) wire it up explicitly, or you'll fly blind in production.
  • !grape-swagger's generated OpenAPI is not free — it walks every endpoint at boot. Cache the doc at build time if boot latency matters.
  • !When mounted in Rails, Grape does NOT go through ApplicationController — session, CSRF and current_user helpers are unavailable. Use a shared middleware instead.

Official resources

Docs, repos, and training materials for this framework.

Related guides

Ready?
Ship a Grape API today

Cloud Run and Heroku are the fastest starts; Fargate is the answer if you already live in AWS. All three run the same 120 MB container.