GithubHelp home page GithubHelp logo

polling-app-server's Introduction

Simple Polling App

A simple polling app based on the mean stack.

Default domain:- localhost. Default port:- 3000.

":" indicates variable names. "()" contains data-type.

URL Formats:-

  1. http://domain:port/home :- GET all the static files.
  2. http://domain:port/api/:post_id/:(true or false) :- GET request for the post details and the status.
  3. http://domain:port/home/api/question :- POST the post details along with the options.
  4. http://domain:port :- The socket.io server location.

JSON Data Formats according to request response scenarios.

  1. Response JSON for the GET request for the post details. 1.1. object.topic_name :- topic name(String). 1.2. object.options :- options(Array of String keyed and Number Valued pairs). 1.3. object.status :- true or false(String). 1.4. object.options[someoptionName] :- Vote Count i.e. by default 0(Number).

NOTE :- Object.keys(res.options[i])[0] is to be done to get particular key names from the options array while iterating through it, where i is the current option key value object.

  1. POST question details. 2.1. object.value:- Topic Name(String). 2.2. object.options:- Options(Array).

  2. Socket events and request parameters's format table:-


eventname parameter(s)  objectvars                               Emitted By
----------------------------------------------------------------------------
join      post_id      post_id(String)                             Client
vote      object       post_id(String),option(String)              Client
updateUI  object       post_id(String),option(String),vote(Number) Server

create-cookie object post_id(String),browser_id(String) Server

Client Script for socket event handling.

<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.1.1/socket.io.dev.js"></script>

var socket = io.connect('http://localhost:3000'); //client socket reference

function broadcast(innerhtml){ //onClick of the option should call this method by providing option's innerHTML
let data={}; data["post_id"]=recieved_post_id; data["option"]=innerhtml; data = JSON.stringify(data); data = JSON.parse(data); socket.emit("join",data["post_id"]); socket.emit("vote",data); } socket.on("updateUI",function(data){
console.log("Server gave="+data); //update the UI when a vote has been registered in server }); socket.on("create-cookie",function(cookie){ //create the localhost file with post_id:hash key value object console.log("create cookie for "+cookie.post_id+"for browser id"+cookie.browser_id); });

PLEASE REFER TESTS FOLDER FOR EXAMPLES BY ROUTING TO /TESTS/<INSERTEXAMPLENAME.HTML>

polling-app-server's People

Contributors

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