This is an example application showing how to use grape on Rack to create a simple API using ROAR along with grape-swagger. This sample shows how to create a simple API without authentication, caching, etc.
The sample was developed using the following
- JRuby 1.17.19
- OS X 10.10.2
- Rack
- grape
- ROAR
- grape-swagger
Gem installation
bundle install --path .bundle/gems --binstubs .bundle/bin
Create and migrate
bundle exec rake db:migrate
bundle exec rake db:migrate RACK_ENV=test
Seed data
bundle exec rake db:seed
bundle exec rake spec
Start the server
bundle exec puma
Getting all todos
curl -i http://localhost:9292/v1/todos
Getting all todos (include todo items)
curl -i http://localhost:9292/v1/todos?type=all
Getting a single todo
curl -i http://localhost:9292/v1/todos/1
Getting a single todo (include todo items)
curl -i http://localhost:9292/v1/todos/1?type=all
Getting the items for a todo
curl -i http://localhost:9292/v1/todos/1/items
Failure to get an item
curl -i http://localhost:9292/v1/items/999
Upload a binary file
curl -X POST -i -F binary_file=@packers.png http://localhost:9292/v1/binary
First, install Swagger UI somewhere locally.
git clone https://github.com/wordnik/swagger-ui.git
Make sure the app server is running
bundle exec puma
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:9292/swagger_doc
From here, you'll be able to explore the API through the Swagger UI.