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
-
Install dependencies
$ bundle install
-
Watch the specs pass
$ bin/rspec spec/api ... 0 failures
- Ruby version: 2.3.1
- Rails version: 5.0
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 paste http://localhost:3000/api/v1/swagger_doc.json to explore the API.
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