Technologies • Dependencies • Getting Started • API Endpoints • Contribute
A backend system for managing polls, enabling users to create, vote, and view polls dynamically with secure APIs.
- Node.js
- Express.js
- MongoDB
- bcrypt
- cors
- dotenv
- express
- jsonwebtoken
- mongoose
Follow the steps below to run the project locally:
How to clone your project
git clone https://github.com/Sharifa26/Poll_backend.git
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
install dependencies
npm install
run the project
npm start
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 |
CURL
curl --location 'https://localhost:2500/register' \
--header 'Content-Type: application/json' \
--data '{
"username": "sharifa",
"password": "sharifa26",
"age": 23,
"gender": "female",
"location": "mumbai"
}'
CURL
curl --location 'https://localhost:2500/login' \
--header 'Content-Type: application/json' \
--data '{
"username": "sharifa",
"password": "sharifa26"
}
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 |
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"]
}
curl --location 'https://localhost:2500/polls' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <token>' \
curl --location 'https://localhost:2500/polls/:id/vote' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <token>' \
--data '{
"option": "red"
}
Contributions are always welcome!
If you'd like to contribute to this project, follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix:
git checkout -b feature/YourFeatureName
. - Make your changes and commit them:
git commit -m "Add your message here"
. - Push your branch to your forked repository:
git push origin feature/YourFeatureName
. - 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