This is a demo rails API application with JWT authenticaiton that exposes CRUD endpoings to manage employees.
In order to set up the project just download this repo and run the following commands:
- Install the dependencies:
bundle install
- We need to set up the database. It automatically feeds some data so that we can use the project right away.
bin/rails db:setup
- Start the server:
bin/rails s
I have created mocked data that are persisted in the database that we can query against.
To use the application you can use an API client like insomnia ###Endpoints
First we need to authenticate. I have created a dummy user with these credentials:
POST http://localhost:3000/login
Params:
email: "me@email.me"
password: "password1!"
We can get our tenant info here:
GET http://localhost:3000/api/v1/tenants
We can get our tenant's employees info here:
GET http://localhost:3000/api/v1/employees
This endpoint also support pagination and search functionality. For pagination we are using url params and in the headers we can see in what page we currently are and what the totals are:
GET http://localhost:3000/api/v1/employees?page=5
This functionality can also be combined with the searching functionality. In order to search we can still use url params to narrow down the results.
Examples:
GET http://localhost:3000/api/v1/employees?name=Minh
GET http://localhost:3000/api/v1/employees?role=sales&page=5
We can create new employees:
POST http://localhost:3000/api/v1/employees
Params:
{
"name": "Michael Scott",
"role": "sales",
"email": "michael@dsd.com",
"tenant_id": "1"
}
We can create new employees:
PATCH http://localhost:3000/api/v1/employees/1
Params:
{
"name": "Michael Scott",
"role": "sales",
}
We can create new employees:
DELETE http://localhost:3000/api/v1/employees/1
In order to run the tests we just have to run:
rspec