An open API service indexing awesome lists of open source software.

https://github.com/rohit31-ui/quiz-app

A backend API for a Quiz Application that allows creating quizzes, adding questions with multiple options, fetching quizzes and questions, and supports single-choice, multiple-choice, and text-based questions.
https://github.com/rohit31-ui/quiz-app

dotenv expressjs mongodb mongoose nodejs

Last synced: 2 months ago
JSON representation

A backend API for a Quiz Application that allows creating quizzes, adding questions with multiple options, fetching quizzes and questions, and supports single-choice, multiple-choice, and text-based questions.

Awesome Lists containing this project

README

          

# ๐ŸŽฏ Quiz Application Backend

---

## ๐Ÿ“– Project Description
This is a **simple backend API** for a Quiz Application. It allows you to:

- โœ… Create quizzes with a title
- โœ… Add questions to quizzes, including multiple options, and mark correct answers
- โœ… Fetch all quizzes
- โœ… Fetch all questions (with options) for a specific quiz

The API supports:
- **Single-choice questions**
- **Multiple-choice questions**
- **Text-based questions** (with a 300-character limit)

---

## ๐Ÿ› ๏ธ Setup Instructions (Run Locally)

### 1๏ธโƒฃ Clone the repository
```bash
git clone
cd Quiz-Application-Backend/server
```

### 2๏ธโƒฃ Install dependencies
```bash
npm install
```

### 3๏ธโƒฃ Create `.env` file
Add the following variables in `.env` file:
```env
MONGODB_URL=mongodb://localhost:27017/quiz
PORT=3000
```

### 4๏ธโƒฃ Start the server
```bash
# Using nodemon
nodemon server.js

# Or using npm script if added
npm run dev
```

**API Base URL:**
```
http://localhost:3000/api
```

---

## ๐Ÿš€ API Endpoints

| Method | Endpoint | Description |
|--------|---------|-------------|
| POST | /api/quizzes | Create a new quiz |
| POST | /api/quizzes/:quizId/questions | Add a question (with options) to a quiz |
| GET | /api/quizzes | Get all quizzes |
| GET | /api/quizzes/:quizId/questions | Get all questions (with options) for a quiz |

---

## ๐Ÿงช Running Test Cases

You can test the API using **Postman** or **VS Code REST Client**.

### 1๏ธโƒฃ Create Quiz
**POST** `/api/quizzes`
**Body:**
```json
{
"title": "JavaScript Basics"
}
```

### 2๏ธโƒฃ Add Question
**POST** `/api/quizzes/:quizId/questions`
**Body:**
```json
{
"text": "What is the output of 1 + '1' in JavaScript?",
"type": "single",
"options": [
{ "text": "11", "isCorrect": true },
{ "text": "2", "isCorrect": false }
]
}
```

### 3๏ธโƒฃ Get All Quizzes
**GET** `/api/quizzes`

### 4๏ธโƒฃ Get Quiz Questions
**GET** `/api/quizzes/:quizId/questions`

---

## ๐Ÿ’ก Assumptions and Design Choices

- **Schemas**: Three separate schemas (`Quiz`, `Question`, `Option`) to keep data normalized
- **Question Types**: Supports `single`, `multiple`, and `text`
- **Option Correctness**: Correct answers stored using `isCorrect` field in `Option`
- **Validation**:
- Single-choice questions must have exactly one correct option
- Multiple-choice questions must have at least one correct option
- Text questions limited to 300 characters
- **Database**: MongoDB (local or cloud instance)

---

## ๐Ÿ› ๏ธ Tech Stack

- Node.js
- Express.js
- MongoDB
- Mongoose
- dotenv

---

## ๐Ÿ”— GitHub Repository
- [quiz app](https://github.com/Rohit31-ui/Quiz-app.git)

---

## ๐Ÿ“ซ Contact

- **Email:** [rohitlad012@gmail.com](mailto:rohitlad012@gmail.com)
- **LinkedIn:** [https://www.linkedin.com/in/rohit-lad-1550b4259/](https://www.linkedin.com/in/rohit-lad-1550b4259/)