zenbakiak / rails-microservice-prototype

Sample prototype for building Microservice with Rails and JWT

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rails Microservice API Gateway prototype

This is mixing up of some API designs for microservice using Rails and JWT. In this design, API endpoints are configured in database and loaded in Rails router. Everytime a new route added or old route updated, Rails router will be reloaded automatically.

Rails-Microservice-Prototype

Setting up

API Gateway

cd Rails-API-Auth
# edit config/database.yml
rake db:create db:migrate db:seed
rails s -p 5000

Post service

cd post_service
rake db:create db:migrate db:seed
rails s -p 5001

Testing using postman

POST http://localhost:5000/user_token
# body raw data
{
  "auth": {
    "email": "joe@localhost.com",
    "password": "pass123456"
  }
}

# sample response
{
    "jwt": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1MzczMjc0OTgsInN1YiI6MX0.hr29yv10mdTgXEFE84YZCjVAD-8bIGOI3Dh7h415wCM"
}

# Sample auth
GET http://localhost:5000/auth
# with headers
Content-Type: application/json
Authorization: Bearer <generated_jwt_above>

# Query post service
GET http://localhost:5000/api/v1/posts
# with headers
Content-Type: application/json
Authorization: Bearer <generated_jwt_above>

References:

About

Sample prototype for building Microservice with Rails and JWT


Languages

Language:Ruby 86.4%Language:HTML 9.1%Language:CSS 2.4%Language:JavaScript 1.4%Language:Shell 0.4%Language:CoffeeScript 0.3%