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
- Rails 4.1.4
- Ruby 2.1.0p0
- OS X 10.9.4
- Grape (0.8.0)
- 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
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
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.