Skip to content

philcallister/rails-grape-entity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Rails 4 + Grape API + Grape Entity + Swagger

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published