Code Monkey home page Code Monkey logo

polls-backend's Introduction

Polls Backend

This is a simple backend application built with Node.js and Fastify that allows users to create, view, and vote on polls. It utilizes TypeScript for type safety, Fastify as the web framework, Prisma ORM for database interaction with PostgreSQL and Redis services managed via Docker, Zod for data validation, and WebSocket for real-time communication.

Diagram

Diagram

Features

  • Create a new poll with multiple options.
  • View existing polls and their options.
  • Vote on a poll option.
  • Unique user identification using UUID to prevent multiple votes.

Technologies Used

  • Node.js
  • Fastify
  • TypeScript
  • Prisma ORM
  • Docker
  • PostgreSQL
  • Redis
  • Zod
  • WebSocket

Installation

  1. Clone the repository:
git clone https://github.com/duardoliveiras/polls-backend.git
  1. Navigate to the project directory:
cd polls-backend
  1. Install dependencies:
npm install
  1. Set up environment variables (if needed).

  2. Start the application:

npm run

Usage

  1. Create a new poll:

    • Endpoint: /polls
    • Method: POST
    • Example: http://localhost:3000/polls
    • Request body should contain poll question and options.
     {
         "title":"Question?",
         "options": ["option1", "option2"]
     }   
    
  2. View one poll:

    • Endpoint: /poll/:id
    • Example: http://localhost:3000/poll/:id
    • Method: GET
  3. Vote on a poll:

    • Endpoint: /polls/:id/vote
    • Method: POST
    • Example: http://localhost:3000/poll/:id/vote
    • Request body should contain the option ID to vote on.
     {
         "pollOptionId" : "b52367ad-721f-42df-86fb-5a7ffea5563e"
     }
    
  4. Web Socket on poll votation:

    • Endpoint: /poll/:id/result
    • Example: ws://localhost:3000/poll/:id/results
    • Every time that ocurr a vote on a poll, the result will be sent to the client.
     {
        "pollOptionId": "37631074-73dd-4910-be87-d75d2739362a",
        "votes": 2
     }
    

polls-backend's People

Contributors

duardoliveiras 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.