This API is a simple web API where you make CRUD calls to a server to organize questions and their answers.
You can use this API in conjunction with my front-end introvert or extrovert app: see the repo
- Ruby on Rails
- ActiveRecord
- PostgreSQL
- Jbuilder
- Rubocop
To get a local copy up and running follow these simple example steps.
- Ruby version: 3.2.1
- Ruby on Rails version: 7.0.3.1
Run the following coammnds in your terminal:
git clone https://github.com/medaminedev66/introvert-or-extrovert-api.git
cd introvert-or-extrovert-api
bundle install
# create migrations with activerecord
rails db:migrate
# if you would like to use seed data
rails db:seed
# start server
rails s
RoR uses port 3000 by default
Quiestion --------------< Answer
:text :question_id
:text
:correct
- has many answers
- belongs to a question
You can make all CRUD calls for the questions database and Create and Destroy questions
- CREATE questions
- GET/RETRIEVE all questions
- GET/RETRIEVE an individual question
- DELETE a question
- UPDATE a question
- CREATE a question
- DESTROY a question
routes
Rails.application.routes.draw do
namespace :api, defaults: { format: :json } do
namespace :v1 do
resources :questions, only: [:create, :index, :show, :destroy, :update]
end
end
end
Shows you a question and all of the answers associated with the question
fetch('/api/v1/questions/2').then((res) => res.json())
.then((data) => console.log(data));
// output
{
"id": 2,
"question": "You’ve been sitting in the doctor’s waiting room for more than 25 minutes. You:",
"answers": [
{
"id": 5,
"text": "Look at your watch every two minutes",
"corret": true
},
{
"id": 6,
"text": "Bubble with inner anger, but keep quiet",
"corret": false
},
{
"id": 7,
"text": "Explain to other equally impatient people in the room that the doctor is always running late",
"corret": false
},
{
"id": 8,
"text": "Complain in a loud voice, while tapping your foot impatiently",
"corret": false
}
]
}
- CREATE an answer
- DELETE an answer
- UPDATE an answer
fetch('/api/v1/answers', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
answer: {
text: "How are you",
correct: true,
question_id: 2,
},
}),
}).then((res) => {
if (res.ok) {
} else {
throw new Error(`API error! status: ${res.status}`);
}
};
// output
{
id: 1,
}
👤 Amine Smahi
- GitHub: @medaminedev66
- Twitter: @medaminesmahi
- LinkedIn: Amine Smahi
Contributions, issues, and feature requests are welcome!
Feel free to check the issues page.
Give a ⭐️ if you like this project!
This project is MIT licensed.