This repo demonstrates how to build an API with Grape that is documented with Swagger and tested with Rspec/Airborne.
To set up the project locally:
- Clone the repo.
cd
into the repo directory on your machine.- run
bundle install
Next, to start the API server:
bundle exec rackup
Now you can curl the API:
curl localhost:9292/api/books
To access the Swagger doc that is generated automatically with the grape-swagger
gem, navigate your browser to
http://localhost:9292/api/swagger_doc.
When you curl the API's books
endpoint, you will get an empty array. That's because that endpoint,
defined in api/books.rb:15
, simply returns an empty array. If you would like to change this behavior,
modify this action.
If you would like to utilize an ORM like ActiveRecord to access and return book
records from a database
(you can see an example of this type of behavior on api/books.rb:10
), you will need to implement this yourself.
See this section in Grape's README
to add ActiveRecord to this project. You can also check out the grape-activerecord
gem:
https://github.com/jhollinger/grape-activerecord