Skip to content

BestCoderDotInfo/RESTful-API-with-JWT-for-Rails-5-Example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Real Time Chat Application using ActionCable

Introduce:

  • Rails 5.0.2
  • Postgres

Features:

  • Sign In/Sign Up/Sign Out
  • Chat Room
  • Chat together: A & B or B & A
  • Send message to Chat Room via API

Setup:

bundle install

rails db:create

rails db:migrate

rails db:seed

AactionCable Added:

Testing

Go live demo

Testing with API :

We using Postman:

  1. We need login to get auth_token :

https://minhquan-todo-app.herokuapp.com/login wiht params:

After login we have auth_token:

{
  "auth_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjozLCJleHAiOjE0OTQ5MzE4ODV9.3fyWCrt4qhL59CiBGWJZEuZSIUGfXey5hY2rc0VEwcU"
}
  1. Using API to post comment:

https://minhquan-todo-app.herokuapp.com/comments

with params:

  • comment[body] : Cotent of message
  • comment[chat_room_id] : ChatRoomID you want send message (1->5)

Headers:

  • Authorization: auth_token (eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjozLCJleHAiOjE0OTQ5MzE4ODV9.3fyWCrt4qhL59CiBGWJZEuZSIUGfXey5hY2rc0VEwcU)

If it successfully, we have:

{
  "id": 8,
  "body": "Send from live API",
  "created_at": "2017-05-15T10:57:22.633Z",
  "user": {
    "id": 3,
    "email": "user2@email.com",
    "created_at": "2017-05-15T10:46:34.729Z",
    "updated_at": "2017-05-15T10:46:34.729Z"
  }
}