Giter Club home page Giter Club logo

pollingapirevamp's Introduction

Polling API Backend with User Authentication and Role-Based Access Control

The Polling API Backend is a Node.js application that serves as the backend for a polling system. It provides endpoints for creating questions, managing options, user authentication using JSON Web Tokens (JWT), and role-based access control (RBAC) for certain actions.

Table of Contents

  1. Features
  2. Technologies Used
  3. Installation
  4. Usage
  5. API Endpoints
  6. Authentication
  7. Authorization
  8. Contributing
  9. License

Features

  • Question Management: Create, view, and retrieve questions.
  • Option Management: Add options to questions and delete options.
  • User Authentication: Register, login, and receive JWT tokens for authentication.
  • Role-Based Access Control (RBAC): Differentiate between administrators and regular users for specific actions.

Technologies Used

  • Node.js
  • Express.js
  • JavaScript
  • MongoDB
  • JSON Web Tokens (JWT) for authentication

Installation

  1. Clone the repository:

    git clone https://github.com/deepak5204/PollingAPIRevamp.git
    
  2. Navigate to the project directory:

    cd pollingAPIRevamp
    
  3. Install dependencies:

    npm install
    
  4. Set up environment variables. Create a .env file in the root directory and add the following:

    - PORT=5000
    - MONGODB_URI=your_mongodb_connection_string
    - JWT_SECRET=your_jwt_secret_key
    - JWT_EXPIRESIN = 5h

Replace your_mongodb_connection_string with your MongoDB connection string and your_jwt_secret_key with a secret key for JWT token generation.

  1. Start the server:
    npm start
    

Usage

To use the API, you can interact with it using tools like Postman, cURL, or any other HTTP client.

API Endpoints

Authentication

  • Only administrators can create, update, and delete questions and options.

  • Regular users have view-only access to questions and options.

  • POST /v2/user/signup: Register a new user.

    curl -X POST http://localhost:5000/v2/user/signup \
--header 'Content-Type: application/json' \
--data-raw '{
    "name": "exampleuser",
    "email": "[email protected]",
    "phoneNo": "123456789",
    "password": "examplepassword"
}'

This command sends a POST request to the '/v2/user/signup' endpoint with a JSON payload containing the user's name, email, phone number, and password. It registers a new user with the provided information.
  • POST /v2/user/login: Login and get a JWT token.
    curl -X POST http://localhost:5000/v2/user/login \
--header 'Content-Type: application/json' \
--data-raw '{
    "email": "[email protected]",
    "password": "examplepassword"
}'

This command sends a POST request to the '/v2/user/login' endpoint with a JSON payload containing the user's email and password. It authenticates the user and returns a JWT token if the credentials are valid.

Make sure to replace http://localhost:5000 with the actual base URL of your API server.

Questions

  • POST /v2/question : Create a new question.
  • GET /v2/question/:questionId : Get a specific question by ID.
  • GET /v2/question : Get all questions.
  • DELETE /v2/question/:questionId : Delete a specific question by ID.

Options

  • POST /v2/option/:questionId : Add an option to a question.
  • GET /v2/option/addvote/:optionId : Add vote an option for a question.
  • DELETE /v2/option/:optionId : Delete an option from a question.

pollingapirevamp's People

Contributors

deepak5204 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.