Skip to content

Latest commit

 

History

History
77 lines (59 loc) · 2.06 KB

README.md

File metadata and controls

77 lines (59 loc) · 2.06 KB

Quiz Application API

This is a RESTful API for managing quizzes, built with Node.js, Express.js, and MongoDB.

Features

  • Create a Quiz: Allows users to create quizzes with questions, multiple-choice options, and correct answers.
  • Retrieve Active Quiz: Fetches the currently active quiz based on the date and time.
  • Get Quiz Result: Retrieves the result of a quiz after it has finished.
  • Get All Quizzes: Fetches a list of all quizzes, including those that are upcoming, active, or finished.
  • JWT Authentication: Secures the API endpoints.
  • Rate Limiting: Limits the number of requests to certain endpoints.

Tech Stack

  • Backend: Node.js, Express.js
  • Database: MongoDB
  • Authentication: JWT (JSON Web Token)

Installation

  1. Clone the repository:
    git clone https://github.com/your-username/quiz-app.git
  2. Navigate to the project directory:
    cd quiz-app
  3. Install dependencies:
    - npm i express nodemon bcrypt mongoose jsonwebtoken dotenv express-rate-limit
    - npm install node-cron
  4. Set up environment variables in a .env file:
    PORT=8080
    MONGO_URI=your_mongodb_connection_string
    
  5. Start the server:
    npm run server

API Endpoints

Authentication

  • POST /auth/register - Registers a new user.
  • POST /auth/login - Logs in an existing user.

Quizzes

  • POST /quizzes - Creates a new quiz (requires authentication).

    • Headers:

      Authorization: Bearer <token>
    • Body:

      {
        "question": "What is the capital of France?",
        "options": ["Berlin", "Madrid", "Paris", "Rome"],
        "rightAnswer": 2,
        "startDate": "2024-08-30T10:00:00Z",
        "endDate": "2024-09-01T10:10:00Z"
      }
  • GET /quizzes/active - Retrieves the currently active quiz.

  • GET /quizzes/:id/result - Retrieves the result of a specific quiz (requires authentication).

  • GET /quizzes/all - Retrieves all quizzes (requires authentication).