Skip to content

Rails implementation of a Node.js API I created in 2023 as a side project for a friend's business. Used as a testing ground to get reacquainted with Ruby / Rails and JWT authentication, as well as picking up RSpec for testing.

RhysMalyon/shiro-rails

Repository files navigation

Shiro API

A booking API developed in Ruby on Rails and authenticated with a JWT-based system using the devise-jwt gem.

Documentation is still WIP.

Setup

Install gems:

bundle install

Set up your database:

rails db:create
rails db:migrate

Seed your database (Optional - includes dummy user for authentication login, as well as customers, appointments, and Japanese national holidays):

rails db:seed

Testing (for documentation mode add the -fd flag to the end):

rspec

Running the project

In your terminal:

rails server

Routes

Authorization


Creating new user

POST /signup
Overview

Registers a new user with the credentials provided in the parameters. These credentials can be used to sign in and access authorization-protected routes. A JWT Bearer token is returned in the response's authorization header.

Parameters
name type data type description
email required string User email
password required string User password
Responses
http code content-type response
201 text/plain;charset=UTF-8 Signed up successfully
400 application/json {"code":"400","message":"User couldn't be created successfully. <current_user.errors.full_messages>"}
Example cURL
curl --location 'http://localhost:3001/signup' \
      -H 'Content-Type: application/json' \
      --data-raw '{
          "user": {
              "email": "test@test.com",
              "password": "test1234"
          }
      }'

Login

POST /login
Overview

Sign a user in using existing credentials. Returns a JWT Bearer token in the response's authorization header that can be used in protected routes' request headers.

Parameters
name type data type description
email required string User email
password required string User password
Responses
http code content-type response
200 text/plain;charset=UTF-8 Logged in successfully.
401 application/json {"code":"401","message":"Invalid Email or password"}
Example cURL
curl --location 'http://localhost:3001/login' \
      -H 'Content-Type: application/json' \
      --data-raw '{
          "user": {
              "email": "test@test.com",
              "password": "test1234"
          }
      }'

Logout

DELETE /logout
Overview

Sign a user out of a session. Requires a valid JWT Bearer token in the request's authorization header (received in response headers from either POST /login or POST /signup).

Parameters

None

Responses
http code content-type response
200 text/plain;charset=UTF-8 Logged out successfully.
401 application/json {"code":"401","message":"Not authorized to access that route."}
Example cURL
curl -L -X DELETE 'http://localhost:3001/logout' \
     -H 'Authorization: Bearer <auth_token>' 

About

Rails implementation of a Node.js API I created in 2023 as a side project for a friend's business. Used as a testing ground to get reacquainted with Ruby / Rails and JWT authentication, as well as picking up RSpec for testing.

Topics

Resources

Stars

Watchers

Forks

Languages