A nodejs based trivia api
- To run this app locally, you're expected to have Nodejs already installed on your device. From the root directory run the following commands to install all the project dependencies.
npm install- To run the app in development, run
npm run devRunning the app in development allows you to have hot reloads. i.e reload on save.
- To start the app in production, simply run
npm startYou are required to specify the following environment variables to run the app successfully. You can specify these variables in a .env file or via shell.
MONGO_URI = <your-mongodb-uri>The data models represented below are modelled using mongoose.
| Title | Type | Unique | Required | Description |
|---|---|---|---|---|
| _id | ObjectId |
true |
true |
The unique identifier automatically generated by mongoose for each document |
| name | String |
true |
true |
The name of the category e.g Science |
| Title | Type | Unique | Required | Description |
|---|---|---|---|---|
| _id | ObjectId |
true |
true |
The unique identifier automatically generated by mongoose for each document |
| description | String |
false |
true |
The content or body of the question. |
| category | ObjectId |
false |
true |
The id of the category this question belongs to. |
| answer | String |
false |
true |
The answer to this question |
- This endpoints returns an array of all categories. Sample response
{
"categories": [
{ "_id": "2", "name": "Science" },
{ "_id": "6", "name": "Art" }
],
"success": true
}- This endpoint returns a single category Sample response
{
"category" : {
"_id" : "2",
"name" : "Science"
}
"success" : true
}- It returns all questions under this category
{
"questions": [
{
"_id": "2",
"description": "Who is the president of Nigeria",
"category": "7"
},
{
"_id": "5",
"description": "When was Nigeria's independence",
"category": "7"
}
],
"success": true
}- It takes in a name property.
Sample request payload
{
"name": "Geography"
}Sample response
{
"category": { "_id": "4", "name": "Geography" },
"success": true
}- Deletes the category with an id of :id
Sample response
{
"deleted": 5,
"success": true
}- Edits a categories name
Sample request payload
{
"name": "Geography"
}Sample response
{
"category": { "_id": "4", "name": "Geography" },
"success": true
}