stalniy / rails-cancan-api-example

Simple Rails 5 REST API with cancan
12 stars 7 forks source link

Rails 5 REST API with CanCan

This is an example of API based on Rails5 and CanCan which can be integrated with CASL. Read CASL and Cancan for details

Installation

If you don't have Ruby, install it (e.g., by using rvm and when you finish, just run this:

gem install bundler
bundle install

Then configure database (it uses sqlite3 by default) in config/databse.yml and run migrations and seeds:

rails db:migrate
rails db:seed

Seeds adds 2 users:

API

To login send:

POST /api/session

{
  "email": "admin@freaksidea.com", # or member@freaksidea.com
  "password": "123456"
}

The response will give back JWT token and a list of rules which can be read by CASL

Run rails routes to see the full list of routes. articles and users follows the general REST CRUD scheme.

Run Server

rails s