Table of Contents
- What is Grape?
- Stable Release
- Project Resources
- Installation
- Basic Usage
- Mounting
- Remounting
- Versioning
- Describing Methods
- Configuration
- Parameters
- Parameter Validation and Coercion
- Supported Parameter Types
- Integer/Fixnum and Coercions
- Custom Types and Coercions
- Multipart File Parameters
- First-Class JSON Types
- Multiple Allowed Types
- Validation of Nested Parameters
- Dependent Parameters
- Group Options
- Renaming
- Built-in Validators
- Namespace Validation and Coercion
- Custom Validators
- Validation Errors
- I18n
- Custom Validation messages
- Headers
- Routes
- Helpers
- Path Helpers
- Parameter Documentation
- Cookies
- HTTP Status Code
- Redirecting
- Recognizing Path
- Allowed Methods
- Raising Exceptions
- Exception Handling
- Logging
- API Formats
- Content-type
- API Data Formats
- JSON and XML Processors
- RESTful Model Representations
- Sending Raw or No Data
- Authentication
- Describing and Inspecting an API
- Current Route and Endpoint
- Before, After and Finally
- Anchoring
- Using Custom Middleware
- Writing Tests
- Reloading API Changes in Development
- Performance Monitoring
- Contributing to Grape
- License
- Copyright
What is Grape?
Grape is a REST-like API framework for Ruby. It's designed to run on Rack
or complement existing web application frameworks such as Rails and Sinatra by
providing a simple DSL to easily develop RESTful APIs. It has built-in support
for common conventions, including multiple formats, subdomain/prefix restriction,
content negotiation, versioning and much more.
Stable Release
You're reading the documentation for the next release of Grape, which should be 1.3.1.
Please read UPGRADING when upgrading from a previous version.
The current stable release is 1.3.0.
Project Resources
- Grape Website
- Documentation
- Need help? Try Grape Google Group or Gitter
- Follow us on Twitter
Installation
Ruby 2.4 or newer is required.
Grape is available as a gem, to install it just install the gem:
gem install grape
If you're using Bundler, add the gem to Gemfile.
gem 'grape'
Run bundle install
.
Basic Usage
Grape APIs are Rack applications that are created by subclassing Grape::API
.
Below is a simple example showing some of the more common features of Grape in
the context of recreating parts of the Twitter API.
module Twitter
class API < Grape::API
version 'v1', using: :header, vendor: 'twitter'
format :json
prefix :api
helpers do
def current_user
@current_user