Welcome to the Challenge API! This is a RESTful API designed for managing polls with real-time voting updates using WebSockets. It provides a simple yet powerful way to create, manage, and participate in polls. Whether you're building a voting application or need a backend for your polling feature, this API has you covered.
- Features
- Technologies Used
- Installation
- Usage
- API Endpoints
- Real-time Voting Updates
- Testing
- Contributing
- License
- Releases
- Create and Manage Polls: Easily create polls and manage them with various options.
- Real-time Updates: Receive real-time updates for votes using WebSockets.
- User-friendly Interface: Designed with a simple and clean interface for easy interaction.
- Comprehensive Documentation: Well-documented API with examples.
- Secure Voting: Ensures secure and anonymous voting.
This project uses a variety of technologies to ensure high performance and scalability:
- Express: A fast web framework for Node.js.
- Node.js: JavaScript runtime built on Chrome's V8 engine.
- PostgreSQL: A powerful, open-source relational database.
- Prisma: A modern database toolkit.
- Socket.IO: Enables real-time, bidirectional communication.
- Swagger: API documentation tool.
- TypeScript: A typed superset of JavaScript.
- Zod: A TypeScript-first schema declaration and validation library.
To get started with the Challenge API, follow these steps:
-
Clone the Repository:
git clone https://github.com/darell444/challenge-api.git cd challenge-api
-
Install Dependencies:
npm install
-
Set Up the Database: Ensure you have PostgreSQL installed and running. Create a database and update the
.env
file with your database credentials. -
Run the Application:
npm run start
Your API will be running on http://localhost:3000
.
You can interact with the API using tools like Postman or curl. Here are some examples of how to use the API.
POST /api/polls
Content-Type: application/json
{
"title": "Favorite Programming Language",
"options": ["JavaScript", "Python", "Java", "C++"]
}
GET /api/polls
POST /api/polls/:pollId/vote
Content-Type: application/json
{
"option": "JavaScript"
}
Here’s a list of the main API endpoints available:
Method | Endpoint | Description |
---|---|---|
GET | /api/polls |
Retrieve all polls |
POST | /api/polls |
Create a new poll |
GET | /api/polls/:pollId |
Retrieve a specific poll |
POST | /api/polls/:pollId/vote |
Vote on a specific poll |
DELETE | /api/polls/:pollId |
Delete a specific poll |
One of the key features of the Challenge API is real-time voting updates. By using WebSockets, the API allows clients to receive updates as votes are cast.
- When a user votes, the server updates the poll data.
- The server then broadcasts the updated poll data to all connected clients.
- Clients can listen for these updates and refresh their UI accordingly.
Here’s a simple example of how to connect to the WebSocket server:
const socket = io('http://localhost:3000');
socket.on('pollUpdated', (poll) => {
console.log('Poll updated:', poll);
// Update the UI with the new poll data
});
To ensure the API works as expected, you can run tests using the following command:
npm run test
Make sure to have a test database set up in your environment variables.
We welcome contributions to the Challenge API! If you have suggestions or improvements, please fork the repository and submit a pull request.
- Fork the repository.
- Create a new branch:
git checkout -b feature/YourFeature
- Make your changes and commit them:
git commit -m 'Add some feature'
- Push to the branch:
git push origin feature/YourFeature
- Open a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
For the latest releases, please visit Releases. You can download the latest version and execute it as needed.
Thank you for checking out the Challenge API! We hope it meets your needs for managing polls and real-time voting updates. If you have any questions or feedback, feel free to reach out or contribute to the project.