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, Course and Favourite. 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://desolate-cove-81044.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://desolate-cove-81044.herokuapp.com/users
curl -X GET \
https://desolate-cove-81044.herokuapp.com/users \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-d 'username=user&password=asdfgh'
[
{
"id": 31,
"first_name": "Muhammad",
"last_name": "Umer",
"username": "ator",
"user_type": "author",
"email": "[email protected]"
},
{
"id": 33,
"first_name": "Muhammad",
"last_name": "Umer",
"username": "user1",
"user_type": "user",
"email": "[email protected]"
}
]
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://desolate-cove-81044.herokuapp.com/login
curl -X POST \
https://desolate-cove-81044.herokuapp.com/login \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-d 'username=user&password=asdfgh'
{
{
"user": {
"id": 30,
"first_name": "Muhammad",
"last_name": "Umer",
"username": "user",
"user_type": "user",
"email": "[email protected]"
},
"token": "eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjozMH0.SFhd9-6MMh5MyurW1vcuigvooMDIxElIJIZLBB2nOf4"
}
This API endpoint return all the Courses.
https://desolate-cove-81044.herokuapp.com/courses/
curl -X GET \
https://desolate-cove-81044.herokuapp.com/courses \
-H 'Authorization: Bearer <Token>' \
-H 'cache-control: no-cache' \
[
{
"course_id": 82,
"title": "React and Redux",
"details": "Avery nice course",
"author": 32,
"requirements": "No Requirements",
"difficulty": "Beginners",
"image": "https://www.wrappixel.com/wp-content/uploads/2019/08/guide-for-react-redux.jpg",
"price": "150",
"date": "2021-03-05T01:41:36.194Z"
}
]
This is the API endpoint related to adding course.
https://desolate-cove-81044.herokuapp.com/courses/
curl -X POST \
https://desolate-cove-81044.herokuapp.com/courses/ \
-H 'Authorization: Bearer <Token>' \
-H 'cache-control: no-cache' \
-d 'title=title&details=details&author=author&requirements=requirements&difficulty=difficulty&image=image&price=price'
- If the appointment was created:
{
"course_id": 82,
"title": "React and Redux",
"details": "Avery nice course",
"author": 32,
"requirements": "No Requirements",
"difficulty": "Beginners",
"image": "https://www.wrappixel.com/wp-content/uploads/2019/08/guide-for-react-redux.jpg",
"price": "150",
"date": "2021-03-05T01:41:36.194Z"
}
- if there was an error:
{
"error": "400 bad request"
}
This is the API endpoint related to adding course to user favourites.
https://desolate-cove-81044.herokuapp.com/courses/:id
curl -X POST \
https://desolate-cove-81044.herokuapp.com/favourites/ \
-H 'Authorization: Bearer <Token>' \
-H 'cache-control: no-cache' \
-d 'user_id=2&course_id:2'
{
"course_id": 2,
"title": "Gulistan E Saadi",
"details": "A very Nice Course",
"author": 2,
"requirements": "No Requirements",
"difficulty": "Intermediate",
"image": "https://www.wrappixel.com/wp-content/uploads/2019/08/guide-for-react-redux.jpg",
"price": "50",
"date": "2021-03-05T04:44:42.928Z"
}
- if empty:
[]
This is the API endpoint related to removing course from user favourites.
https://desolate-cove-81044.herokuapp.com/courses/:id
curl -X POST \
https://desolate-cove-81044.herokuapp.com/favourites/ \
-H 'Authorization: Bearer <Token>' \
-H 'cache-control: no-cache' \
-d 'user_id=30&course_id:82'
{
Removed From Favourites
}
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
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://desolate-cove-81044.herokuapp.com/
.
Reach out to me!
Muhammad Fahad Umer
- LinkedIn: Muhammad Fahad
- Github: @MFahadUmer
- Twitter: @engfahadumer
Contributions, issues, and feature requests are welcome!
Feel free to check the issues page.
- Thanks to Microverse for its support!
- Thanks React Community
- Thanks to Marc-Antoine Roy for his awesome Designs.
- Thanks to behance
Give a โญ๏ธ if you like this project!