Skip to content

micrometre/nexjs-quiz

Repository files navigation

Quiz App

This is a Quiz App built with Next.js and Prisma. It allows users to take quizzes and calculates their scores based on their answers.

Features

  • Fetch all quizzes with questions and answers
  • Submit quiz answers and calculate scores

Setup

  1. Clone the repository:

    git clone https://github.com/micrometre/nexjs-quiz.git
    cd nexjs-quiz
  2. Install dependencies:

    npm install
  3. Set up the database:

    npx prisma migrate dev --name init
  4. Start the development server:

    npm run dev

API Endpoints

GET /api/quizzes

Fetch all quizzes with their questions and answers.

Response

[
  {
    "id": 1,
    "title": "Sample Quiz",
    "questions": [
      {
        "id": 1,
        "text": "Sample Question?",
        "answers": [
          { "id": 1, "text": "Answer 1", "isCorrect": false },
          { "id": 2, "text": "Answer 2", "isCorrect": true }
        ]
      }
    ]
  }
]

POST /api/quizzes

Submit quiz answers and calculate the score

Request

{
  "quizId": 1,
  "answers": {
    "1": 2
  }
}

Response

{
  "score": 1,
  "total": 1
}

License

This project is licensed under the MIT License.

About

Quiz App built with Next.js and Prisma

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published