Rails 4 + Grape API + Grape Entity + Swagger
Ruby HTML CSS JavaScript
Latest commit 5af13ee Sep 16, 2015 @philcallister Plug for ROAR project
Failed to load latest commit information.
app New + Delete Aug 5, 2014
bin Initial Jul 29, 2014
config Swagger Support Jul 29, 2014
db Seed db + documentation Jul 29, 2014
lib Initial Jul 29, 2014
log Initial Jul 29, 2014
public Initial Jul 29, 2014
spec Swagger Support Jul 29, 2014
vendor/assets Initial Jul 29, 2014
.gitignore Initial Jul 29, 2014
.rspec RSpec examples Jul 29, 2014
.ruby-version Ruby version for rbenv Jul 29, 2014
Gemfile Swagger Support Jul 29, 2014
Gemfile.lock Swagger Support Jul 29, 2014
README.md Plug for ROAR project Sep 16, 2015
Rakefile Initial Jul 29, 2014
config.ru Initial Jul 29, 2014


Todo API

This is an example application showing how to use grape to create a simple API using entities with the grape-entity gem. This sample shows how to create a simple API without authentication, caching, etc. It also only shows GET requests. It doesn't update or delete any information. I plan to add a few examples, but this is really just to show how Grape + Grape-Entity work together.

New and Improved: Check out the grape-rack-roar-swagger project! ROAR is very nice. Give a try!


The sample was developed using the following

  1. Rails 4.1.4
  2. Ruby 2.1.0p0
  3. OS X 10.9.4
  4. Grape (0.8.0)
  5. Grape Entity (0.4.3)


Gem installation

bundle install

Create and migrate

rake db:migrate

Seed data

rake db:seed


rake db:test:prepare # deprecated -- not sure why test db still needs to be prepared.  TBD...
bundle exec rspec spec

Run It

Start the Rails server

rails s


Getting all todos

curl -i http://localhost:3000/api/v1/todos

Getting all todos (include todo items)

curl -i http://localhost:3000/api/v1/todos?type=all

Getting a single todo

curl -i http://localhost:3000/api/v1/todos/1

Getting a single todo (include todo items)

curl -i http://localhost:3000/api/v1/todos/1?type=all

Getting the items for a todo

curl -i http://localhost:3000/api/v1/todos/1/items

Failure to get an item

curl -i http://localhost:3000/api/v1/items/999

Swagger Support

First, install Swagger somewhere locally.

git clone https://github.com/wordnik/swagger-ui.git

Make sure the Rails server is running

rails s

From Chrome or Safari, open the locally installed Swagger swagger-ui/dist/index.html file. In the text field that currently lists http://petstore.swagger.wordnik.com/api/api-docs, change this to http://localhost:3000/api/swagger_doc

From here, you'll be able to explore the API through the Swagger UI.