Git Product home page Git Product logo

api-polls's Introduction

API-POLLS

A real-time voting system where users can create a poll and other users can cast their votes. The system generates a ranking among the options and updates the votes in real-time.

Requisites

  • Docker;
  • Node.js;
  • Fastify;
  • Redis;
  • Websocket;

Setup

  • Clone the repository;
  • Setup deploy (docker compose up --build -d);

HTTP

POST /polls

Create a new poll.

Request body

{
  "title": "Qual a melhor fruta?",
  "options": [
    "laranja",
    "maracuja",
    "goiaba"
  ]
}

Response body

{
  "pollId": "194cef63-2ccf-46a3-aad1-aa94b2bc89b0"
}

GET /polls/:pollId

Return data from a single poll.

Response body

{
	"poll": {
		"id": "e4365599-0205-4429-9808-ea1f94062a5f",
		"title": "Qual a melhor fruta?",
		"options": [
			{
				"id": "4af3fca1-91dc-4c2d-b6aa-897ad5042c84",
				"title": "laranja",
				"score": 1
			},
			{
				"id": "780b8e25-a40e-4301-ab32-77ebf8c79da8",
				"title": "maracuja",
				"score": 0
			},
			{
				"id": "539fa272-152b-478f-9f53-8472cddb7491",
				"title": "goiaba",
				"score": 0
			}
		]
	}
}

POST /polls/:pollId/votes

Add a vote to specific poll.

Request body

{
  "pollOptionId": "31cca9dc-15da-44d4-ad7f-12b86610fe98"
}

WebSockets

ws /polls/:pollId/results

Message

{
  "pollOptionId": "da9601cc-0b58-4395-8865-113cbdc42089",
  "votes": 2
}

api-polls's People

Contributors

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