Skip to content

Sharifa26/Poll_backend

Repository files navigation

Poll Backend 🎯

TechnologiesDependenciesGetting StartedAPI EndpointsContribute

A backend system for managing polls, enabling users to create, vote, and view polls dynamically with secure APIs.

💻 Backend Technologies

  • Node.js
  • Express.js
  • MongoDB

📦 Dependencies

  • bcrypt
  • cors
  • dotenv
  • express
  • jsonwebtoken
  • mongoose

🚀 Getting Started

Follow the steps below to run the project locally:

Cloning

How to clone your project

git clone https://github.com/Sharifa26/Poll_backend.git

Config .env Variables

Use the .env.example as a reference to create your .env file with your project configuration.

MONGO_URL = YOUR_MONGODB_URL
PORT = YOUR_PORT
JWT_SECRET = YOUR_JWT_SECRET
FRONT_URL = YOUR_FRONT_URL

Starting

install dependencies

npm install

run the project

npm start

📍 API Endpoints

Here you can list the main routes of your API, and what are their expected request bodies. ​

route description
POST /register register user into the api see request details
POST /login authenticate user into the api see request details
GET /user get user by token see request details

POST /register

CURL

curl --location 'https://localhost:2500/register' \
--header 'Content-Type: application/json' \
--data '{
    "username": "sharifa",
    "password": "sharifa26",
    "age": 23,
    "gender": "female",
    "location": "mumbai"
}'

POST /login

CURL

curl --location 'https://localhost:2500/login' \
--header 'Content-Type: application/json' \
--data '{
    "username": "sharifa",
    "password": "sharifa26"
}

GET /user

curl --location 'https://localhost:2500/user' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <token>' \
route description
POST /polls create poll see request details
GET /polls get polls by user see request details
PUT /polls/:id/vote vote on poll see request details

POST /polls

curl --location 'https://localhost:2500/polls' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <token>' \
--data '{
    "question": "what is your favourite color?",
    "options": ["red", "blue", "green", "yellow"]
}

GET /polls

curl --location 'https://localhost:2500/polls' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <token>' \

PUT /polls/:id/vote

curl --location 'https://localhost:2500/polls/:id/vote' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <token>' \
--data '{
    "option": "red"
}

📫 Contribute

Contributions are always welcome!

If you'd like to contribute to this project, follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix: git checkout -b feature/YourFeatureName.
  3. Make your changes and commit them: git commit -m "Add your message here".
  4. Push your branch to your forked repository: git push origin feature/YourFeatureName.
  5. Open a pull request with a clear description of your changes.

For major changes, please open an issue first to discuss what you'd like to change.

Thank you for your contributions! 🙌

Made with ❤️ by Sharifa26

About

This a Backend code for CRUD operations

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published