Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rhysmalyon/shiro-rails
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.
https://github.com/rhysmalyon/shiro-rails
devise-jwt rails-api rspec
Last synced: about 2 months ago
JSON representation
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.
- Host: GitHub
- URL: https://github.com/rhysmalyon/shiro-rails
- Owner: RhysMalyon
- Created: 2024-01-25T05:20:19.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-02-21T02:19:29.000Z (12 months ago)
- Last Synced: 2024-12-18T17:13:05.447Z (about 2 months ago)
- Topics: devise-jwt, rails-api, rspec
- Language: Ruby
- Homepage:
- Size: 85.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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. "}` |##### Example cURL
> ```javascript
> curl --location 'http://localhost:3001/signup' \
> -H 'Content-Type: application/json' \
> --data-raw '{
> "user": {
> "email": "[email protected]",
> "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
> ```javascript
> curl --location 'http://localhost:3001/login' \
> -H 'Content-Type: application/json' \
> --data-raw '{
> "user": {
> "email": "[email protected]",
> "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
orPOST
/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
> ```javascript
> curl -L -X DELETE 'http://localhost:3001/logout' \
> -H 'Authorization: Bearer '
> ```------------------------------------------------------------------------------------------