Skip to content

Grape

A Ruby framework for building REST-style web APIs with a simple DSL.

Stars
10k
Forks
1.2k
Licence
MIT
Language
Ruby
Last update
5 days ago
Type
Library

What it is

Grape is a framework for building REST-like APIs in Ruby. It runs on Rack and can also sit alongside existing web frameworks such as Rails and Sinatra. It provides a small DSL for defining endpoints and includes built-in support for things like multiple formats, versioning, and content negotiation.

  • Define endpoints for listing, creating, updating and deleting resources, as the Twitter-style example in the README shows
  • Mount a Grape API inside a Rails app under app/api
  • Run a Grape API alongside a Sinatra app using Rack::Cascade
  • Share endpoint code across versions or components by mounting APIs inside each other

Great for

  • Ruby developers who need to build a REST-style JSON API
  • Teams adding an API alongside an existing Rails or Sinatra app
  • Projects that want versioning and mountable API components

Not ideal for

  • People who need a complete web app with views and front-end pages, since Grape focuses on APIs
  • Non-Ruby teams, because it is a Ruby gem
  • Beginners with no Ruby experience, since the README assumes familiarity with Rack and Ruby classes
Step-by-step guide: how to use GrapeInstall, first run, examples, tips and FAQs

How to get it

  1. 1

    Install with a package manager

    You'll need: Ruby 3.3.1 or newer

    Add the gem to your project

    bundle add grape
  2. 2

    Run it

    • Install Ruby 3.3.1 or newer
    • Run bundle add grape in your project
    • Create a class that subclasses Grape::API and define a route such as get :hello
    • Run it as a Rack app with a config.ru file and rackup
  3. 3

    Get the most out of it

    • Call compile! before serving requests to preload routes
    • Use mount with a path or configuration hash to reuse endpoints in multiple places
    • Use rescue_from and error! to handle errors consistently
    • Add desc and params blocks to document and validate endpoints

Downloads

Strengths

  • Simple DSL for defining REST-like routes
  • Built-in support for versioning, formats, and content negotiation
  • Works with Rack and integrates with Rails and Sinatra

Trade-offs

  • Requires Ruby 3.3.1 or newer, which may rule out older projects
  • Mounting alongside other frameworks has ordering rules that can cause surprising 404 behavior if misconfigured
  • The README is truncated, so some details beyond the basics are not covered here

How it compares

ProjectStarsTypeLevelUpdatedBest for
grape (this)10kLibraryintermediate5 days agoRuby developers who need to build a REST-style JSON API
sinatra12.5kLibrarybeginner4 months agoRuby developers who want a small, readable web app or API
chi23kLibraryintermediate19 days agoGo developers building REST API services
fastapi105kLibrarybeginner4 days agoPython developers building JSON APIs or back-end services
hoppscotch80.7kAppbeginner6 days agoDevelopers who want to test REST, GraphQL, WebSocket, or other APIs without a heavy desktop client
imgui76.9kLibraryintermediate6 days agoGame developers who want an in-engine debug or tools panel

Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.