Skip to content

ayo-awe-archive/trivia-api

Repository files navigation

Trivia API

A nodejs based trivia api

Getting started

Starting the app

  • 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 dev

Running the app in development allows you to have hot reloads. i.e reload on save.

  • To start the app in production, simply run
npm start

Environment variables

You 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>

Data models

The data models represented below are modelled using mongoose.

Categories

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

Questions

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

Endpoints

Categories

  • GET /categories

    This endpoints returns an array of all categories. Sample response
{
  "categories": [
    { "_id": "2", "name": "Science" },
    { "_id": "6", "name": "Art" }
  ],
  "success": true
}
  • GET /categories/:id

    This endpoint returns a single category Sample response
{
"category" : {
"_id" : "2",
"name" : "Science"
}
"success" : true
}
  • GET /categories/:id/questions

    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
}
  • POST /categories

    It takes in a name property.

Sample request payload

{
  "name": "Geography"
}

Sample response

{
  "category": { "_id": "4", "name": "Geography" },
  "success": true
}
  • DELETE /categories/:id

    Deletes the category with an id of :id

Sample response

{
  "deleted": 5,
  "success": true
}
  • PATCH /categories/:id

    Edits a categories name

Sample request payload

{
  "name": "Geography"
}

Sample response

{
  "category": { "_id": "4", "name": "Geography" },
  "success": true
}

Questions

  • GET /questions

  • GET /questions/:id

  • POST /questions

  • DELETE /questions/:id

  • PATCH /questions/:id

Play

  • POST /play

About

A nodejs based trivia api

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •