Polls

Supports answering trivia questions and reporting Trivia winners.

  • Each route requires that requests authenticate with a Reactive JWT Token. Refer to our authentication documentation for how to get and use a Reactive JWT Token.
  • You will create trivia questions, we call them quizzes, through the UI in the Reactive Streamer App.
  • Newly created quizzes will be published to the events-stream service in the format below.

Quiz Event Format:

Trivia Question:

{ 
  "type": "quiz",
  "data": {
    "id": "6935357a-8d71-45f2-9a0f-ddaed705b43a",
    "streamId": "1127787a-8d71-45f2-9a0f-ddaed703e4b6z",
    "created": 16000,
    "duration": 10000,
    "closeInterval": 17000,
    "question": "What is the most consumed manufactured drink in the world?",
    "choices": {
      "Coffee": {
        "count": 0,
        "percentage": 0
      },
      "Tea": {
        "count": 0,
        "percentage": 0
      },
      "Soda": {
        "count": 0,
        "percentage": 0
      }
    }
  }
}

Trivia Question Results:

{ 
  "type": "quiz-results",
  "data": {
    "id": "6935357a-8d71-45f2-9a0f-ddaed705b43a",
    "streamId": "1127787a-8d71-45f2-9a0f-ddaed703e4b6z",
    "created": 16000,
    "duration": 10000,
    "closeInterval": 17000,
    "question": "What is the most consumed manufactured drink in the world?",
    "answer": "Tea",
    "choices": {
      "Coffee": {
        "count": 2123,
        "percentage": 1
      },
      "Tea": {
        "count": 55156,
        "percentage": 33
      },
      "Soda": {
        "count": 107721,
        "percentage": 65
      }
    }
  }
}

Answer a trivia question

Request:

POST https://polls.reactive.live/api/v1/quizzes/:quiz-id/answer

Parameters:

Name Type Required Description
quiz-id string Yes The id of the quiz question the client is answering.

Body:

Name Type Required Description
streamId string Yes The id of the stream you're answering in.
choice string Yes The quiz's choice you'd like to select.
closeInterval Integer Yes The interval that the quiz stops accepting answers in. This is provided to you in the quiz event from the events stream service.

Example command:

curl -i  \
  -H "Content-Type: application/json" \
  -X POST \
  -d '{"streamId": "2343567a-8d71-45f2-9a0f-ddaed705bbbq", "choice": "Tea"}' \
  https://polls.reactive.live/api/v1/quizzes/6935357a-8d71-45f2-9a0f-ddaed705b43a/answer

Response:

HTTP 204 NO CONTENT
Allow: GET, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

Report a viewer as a trivia winner

This route allows clients to report themselves as a winner so they can be included in the event winner count.

Clients should make a request to this route when:

  • The client has answered all questions correctly.
  • The client receieves the request-quiz-winners event through the events-stream service.

The request-quiz-winners will be published to the events-stream service with the following strucutre:

{ 
  "type": "request-quiz-winners",
  "data": null
}

Request:

POST https://polls.reactive.live/api/v1/quizzes/:streamId/record-winner

Parameters:

Name Type Required Description
streamId string Yes The id of the stream you'd like to report the client as a winner for.

Example command:

curl -i  \
  -H "Content-Type: application/json" \
  -X POST \
  https://polls.reactive.live/api/v1/quizzes/6935357a-8d71-45f2-9a0f-ddaed705b43a/record-winner

Response:

HTTP 204 NO CONTENT
Allow: GET, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

Events-stream Service Event:

One second after the request-quiz-winners event is published, the events-stream service will publish the stream's winner count in the following event:

{ 
  "type": "quiz-winners",
  "data": {
    "count": 1232
  }
}