This is a Ruby on Rails API from which the React frontend serves the data. It is a simple Rails app that has three models - User, Coach and Appointment. For the authentication of the users I used JSON Web Tokens. The API is hosted on Heroku, at this endpoint: career-coaches-api - But they can only be accessed with a valid API token. The front end can be found here
- Ruby v2.7.0
- Ruby on Rails 6.0.3.4
- Rspec
- JWT
The base URL for all the endpoints is
https://career-coaches-api.herokuapp.com
. All request sent to any of the end-points excepts/users
and/login
are first validated. The validation is done using tokens generated by JWT upon registration or login. These token has to be sent in the headers of the request you are making in order to successfully access those end-points.
This API endpoint is used for registering new users to the system and doesn't require authorization.
https://career-coaches-api.herokuapp.com/users
curl -X POST \
https://career-coaches-api.herokuapp.com/users \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-d 'username=username&email=email&password=password'
{
"user": {
"id": 1,
"email": "email",
"username": "username",
"password_digest": "$2a$12$N.nStVsShl06Y4ClZrazduac91SIp1GMPTwD1/CXLO31RdMtuX1ZK",
"created_at": "2020-11-06T20:06:34.492Z",
"updated_at": "2020-11-06T20:06:34.492Z"
},
"token": "eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjozNX0.nLY4f5bGd_E9dJcpp-p1YdDcbaKasVj9hrP3zlfCkdE"
}
This API endpoint is used for logging in a user into the system and also does not require authorization, just the username and password that was used in creating an account and that will be added to the request body.
https://career-coaches-api.herokuapp.com/login
curl -X POST \
https://career-coaches-api.herokuapp.com/login \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-d 'username=username&password=password'
{
"user": {
"id": 1,
"email": "email",
"username": "username",
"password_digest": "$2a$12$pljN0EuO4Ui/FoKdVfgBhuXkrOEZSTSAHx/KKN8kOUk35IqGm7lwq",
"created_at": "2020-11-01T12:48:45.667Z",
"updated_at": "2020-11-01T12:48:45.667Z"
},
"token": "eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxfQ.oT7kSePnYs7eVIsRIzIi0UEC7XBclsrO3qrnXwic8Zg"
}
This API endpoint is used for automatically logging in a user. It's a get request and reqquires the token generated when the user was created or logged in to be sent along in the request header.
https://career-coaches-api.herokuapp.com/login
curl -X GET \
https://career-coaches-api.herokuapp.com/auto_login \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-H 'Authorization: Bearer <Token>'
{
"user": {
"id": 1,
"email": "email",
"username": "username",
"password_digest": "$2a$12$pljN0EuO4Ui/FoKdVfgBhuXkrOEZSTSAHx/KKN8kOUk35IqGm7lwq",
"created_at": "2020-11-01T12:48:45.667Z",
"updated_at": "2020-11-01T12:48:45.667Z"
},
}
This API endpoint return all the appointments of the user.
https://career-coaches-api.herokuapp.com/appointments
curl -X GET \
https://career-coaches-api.herokuapp.com/appointments \
-H 'Authorization: Bearer <Token>' \
-H 'cache-control: no-cache' \
[
{
"id": 1,
"user_id": 1,
"coach_id": 3,
"date_and_time: "021-01-08T14:00:00.000Z",
"created_at": "2020-11-01T12:51:04.679Z",
"updated_at": "2020-11-01T12:51:04.679Z"
},
{
"id": 2,
"user_id": 1,
"coach_id": 5,
"date_and_time: "021-01-08T14:00:00.000Z",
"created_at": "2020-11-01T12:51:04.679Z",
"updated_at": "2020-11-01T12:51:04.679Z"
}
]
This is the API endpoint related to booking appointments in the system.
https://career-coaches-api.herokuapp.com/appointments
curl -X POST \
https://career-coaches-api.herokuapp.com/appointments \
-H 'Authorization: Bearer <Token>' \
-H 'cache-control: no-cache' \
-d 'coach_id=2&date=021-01-08T14:00:00.000Z'
- If the appointment was created:
{
"message": "Appointment with Hobert Johnston created successfully."
}
- if there was an error:
{
"error": "This will be the error message"
}
This is the API endpoint related to cancelling appointments in the system.
https://career-coaches-api.herokuapp.com/appointments/:id
curl -X POST \
https://career-coaches-api.herokuapp.com/cancel_appointment/:id \
-H 'Authorization: Bearer <Token>' \
-H 'cache-control: no-cache' \
-d 'coach_id=2'
{
"message": "Your appointment with Hobert Johnston has been cancelled."
}
To get a local copy up and running follow these simple example steps.
Ruby: 2.7.0 Rails: 6.0.3.4 Postgres: >=9.5
Install gems with:
bundle install
Setup database with:
rails db:create
rails db:migrate
Populate database with:
rails db:seed
Start server with:
rails server
- You can then proceed to test the different end point via postman or any choice of yours.
Type the following in your terminal/command line to run tests for the API:
rpsec
This API has been deployed on heroku. It is acccessible at https://career-coaches-api.herokuapp.com/
.
π€ Ebeagu Samuuel
- Github: ebeagusamuel
- Twitter: @ebeagu_samuel
- Linkedin: Ebeagu Samuel
Contributions, issues and feature requests are welcome!
Feel free to check the issues page.
Kindly give this repository a βοΈ if you like this project!
-
Project specifications by Microverse.
-
Images downloaded here.
This project is licensed under the MIT License.