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 installCreate and migrate
rake db:migrateSeed data
rake db:seedrake db:test:prepare # deprecated -- not sure why test db still needs to be prepared. TBD...
bundle exec rspec specStart the Rails server
rails sGetting all todos
curl -i http://localhost:3000/api/v1/todosGetting all todos (include todo items)
curl -i http://localhost:3000/api/v1/todos?type=allGetting a single todo
curl -i http://localhost:3000/api/v1/todos/1Getting a single todo (include todo items)
curl -i http://localhost:3000/api/v1/todos/1?type=allGetting the items for a todo
curl -i http://localhost:3000/api/v1/todos/1/itemsFailure to get an item
curl -i http://localhost:3000/api/v1/items/999First, install Swagger somewhere locally.
git clone https://github.com/wordnik/swagger-ui.gitMake sure the Rails server is running
rails sFrom 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.