This is an API build with Rails 6.1.1. for the final capstone project of the technical curriculum in Microverse. You can find the code of the Fun Courses react and redux front-end at this link that uses this API which is capable to store courses, users, friendships, subscriptions, comments, tokens, and favorites. Feel free to fork this project and make your API up and running. If you want to see the JS fetch requests in action are in this two links: here you will find the requests when the app starts and here queries to persist when the user request a subscription, accept or accept a friendship to say a few.
- Rails 6.1.1
- Ruby 2.7.2p137
To start with the project:
- Install Ruby and Ruby on Rails in your machine, it is recommended to use the same versions that use this project.
- Fork this repository.
- Run
bundle install
inside the folder where the app lives. - Run rails db:create
- Because this project relies on Cloudinary vendor for uploading pictures or media to the cloud in all environments, you need to have an account in Cloudinary to run successfully and upload any picture in the local environment. You can find more information about Cloudinary here, and about active storage here.
- This project uses environment variables that provide the credentials to access to Cloudinary, because this is sensitive information that should not be uploaded to source control it is recommended that you set up these variables in your environment named the same as in the file config/initializers/cloudinary.rb.
- Run the migration to database
- rails db:migrate
- Run the rails server
- rails server
This is an example of a request to create a new course using js fetch() in a local development using port 3000:
fetch('https//localhost:3000/courses/create', {
method: 'POST',
mode: 'cors',
cache: 'no-cache',
credentials: 'same-origin',
headers: new Headers({
'Content-Type': 'application/json',
}),
redirect: 'follow',
referrerPolicy: 'no-referrer',
body: JSON.stringify({
current_user_id: 7,
current_user_password: "password",
token_id: 25,
token: "sometoken",
user: {
link: 'link',
provider: 'provider',
title: 'title',
content: 'the content',
status: 'Closed',
dates:, '2021-03-25T00:00:00.000Z 2021-03-29T00:00:00.000Z '
}
}),
})
To create your token just make a curl request like this:
curl --request POST https://floating-earth-85150.herokuapp.com/tokens
Using the main url https://floating-earth-85150.herokuapp.com/ you can go to:
POST /signup(.:format)
POST /user(.:format)
POST /courses(.:format)
POST /courses/create(.:format)
POST /user/friends(.:format)
PATCH /users/:id(.:format)
PUT /users/:id(.:format)
DELETE /users/:id(.:format)
PATCH /courses/:id(.:format)
PUT /courses/:id(.:format)
DELETE /courses/:id(.:format)
POST /friendships(.:format)
PATCH /friendships/:id(.:format)
PUT /friendships/:id(.:format)
DELETE /friendships/:id(.:format)
POST /subscriptions(.:format)
PATCH /subscriptions/:id(.:format)
PUT /subscriptions/:id(.:format)
DELETE /subscriptions/:id(.:format)
POST /favorites(.:format)
DELETE /favorites/:id(.:format)
POST /comments(.:format)
PATCH /comments/:id(.:format)
PUT /comments/:id(.:format)
DELETE /comments/:id(.:format)
POST /tokens(.:format)
DELETE /tokens/:id(.:format)
To see which proper payload should be sent, just check out the controllers which handle the requests. Remember that params
are the data that you need to send out in the fetch inside the body as seen in the above example js fetch request. Please pay special attention to the application_controller.rb file where the methods authenticate
and authenticate_token
take through params the information about user and token to be able to continue the request to the controllers. These are the routes of the controller files in this repo:
./app/controllers/application_controller.rb,
./app/controllers/comments_controller.rb,
./app/controllers/courses_controller.rb,
./app/controllers/favorites_controller.rb,
./app/controllers/friendships_controller.rb,
./app/controllers/susbcriptions_controller.rb,
./app/controllers/tokens_controller.rb,
./app/controllers/tokens_controller.rb
👤 Javier Botero
- Github: @Javierbotero
- Twitter: @Javierbotero1
- Linkedin: Javier Botero
Contributions, issues and feature requests are welcome!
Give a ⭐️ if you like this project!