Skip to content

gagoit/rails5-grape-api-example

Repository files navigation

Rails 5 + Grape API Example

This is an example application using Rails 5 + Grape API

Getting Started

  1. Clone the repo

    $ git clone https://github.com/gagoit/rails5-grape-api-example.git
    $ cd rails5-grape-api-example
    
  2. Install dependencies

    $ bundle install
    
  3. Watch the specs pass

    $ bin/rspec spec/api
    ... 0 failures
    

Dependencies:

  • Ruby version: 2.3.1
  • Rails version: 5.0

Features

Utilize CORS (Cross-Origin Resource Sharing)

I use the rack-cors gem!. This gem provides Rack CORS Middleware to our Rails app, allowing it to support cross-origin resource sharing.

Serializing

Grape::ActiveModelSerializers

Grape Swagger

The grape-swagger gem autogenerates Swagger-compliant documentation for your Grape API.

Versioning

Api Version will be set in headers['Accept'] = "application/vnd.#{vendor}-v#{version}"

Authorization

User Authorization token will be set in headers['Authorization']

Response format:

Normal

{
   data: {},
   meta: {
      code: 200,
      message: "success"
   }
}

Pagination:

{
   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 = 1
  • next_pave = -1 if current_page = last_page

Resources

About

Rails 5 + Grape API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published