Skip to content
Simple Rails 5 REST API with cancan
Branch: master
Clone or download
Pull request Compare This branch is 9 commits ahead of bradtraversy:master.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
app
bin
config feat(cors): adds cors middleware Mar 30, 2018
db feat(cors): adds cors middleware Mar 30, 2018
lib/tasks first commit basic REST Jun 27, 2017
log
public
test refactor(api): converts it to JWT based API Mar 29, 2018
tmp
Gemfile feat(cors): adds cors middleware Mar 30, 2018
Gemfile.lock
README.md docs(README): adds article URL May 28, 2018
Rakefile first commit basic REST Jun 27, 2017
config.ru

README.md

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
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.