Skip to content
Rails 4 + Grape API + Grape Entity + Swagger
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
app
bin
config
db
lib
log
public
spec
vendor/assets
.gitignore
.rspec
.ruby-version
Gemfile
Gemfile.lock
README.md
Rakefile
config.ru

README.md

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!

Environment

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)

Setup

Gem installation

bundle install

Create and migrate

rake db:migrate

Seed data

rake db:seed

Testing

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

Usage

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.

You can’t perform that action at this time.