This is an example application using Rails 5 + Grape API
-
Clone the repo
$ git clone https://github.com/gagoit/rails5-grape-api-example.git $ cd rails5-grape-api-example
-
Setup application
$ bundle $ rails db:setup $ rails s
-
Watch the specs pass
$ rspec ... 0 failures
-
Play around with APIs
$ open http://localhost:300/docs
- Ruby version: 2.3.1
- Rails version: 5.0.0.1
I use the rack-cors gem!. This gem provides Rack CORS Middleware to our Rails app, allowing it to support cross-origin resource sharing.
The grape-swagger gem autogenerates Swagger-compliant documentation for your Grape API.
- Visit http://petstore.swagger.io/ and open http://localhost:3000/swagger_doc to explore the API.
- Open http://localhost:300/docs to play around API documentation powered by grape-swagger-rails gem.
Api Version will be set in headers['Accept'] = "application/vnd.#{vendor}-v#{version}"
User Authorization token will be set in headers['Authorization']
{
data: {},
meta: {
code: 200,
message: "success"
}
}
{
data: {},
meta: {
code: 200,
message: "success",
current_page: 1,
next_page: 2,
prev_page: -1,
total_pages: 2,
total_count: 21
}
}
prev_pave = -1
if current_page = 1next_pave = -1
if current_page = last_page
rails routes
for normal Rails routesrails grape:routes
for Grape generated routes