This project is not covered by Drupal’s security advisory policy.

Overview

The Poll Rest module provides a REST endpoint to retrieve and submit choices or votes based on the Poll module.

Requirements

Post-Installation

  1. Enable poll, rest, and poll_rest modules.
  2. Head over to /admin/config/services/rest and enable the poll vote resource.
  3. Enable the GET, POST, DELETE method.

Usage

GET

The implementation of GET verbose can response options or votes from a poll.

Request options

curl -v http://locahost/api/v1/poll/1?query=choices

Response options
  • `chid`: is the choice id.
  • `name`: is the name of the option.
  • `action`: is the uri to request a vote of a choice
{
  "raw_question":"What development methodology do you use??",
  "pid":"1",
  "user_vote":null,
  "choices":[
  {
    "chid":4,
    "name":"KanBan",
  },
  {
    "chid":5,
    "name":"RUP",
    }]
}
Requests votes

curl -v http://locahost/api/v1/poll/1?query=votes

Response votes
{
  "raw_question":"What development methodology do you use??",
  "total_votes":"1",
  "pid":"1",
  "user_vote":null,
  "results":[
  {
    "choice":"RUP",
    "display_value":"100% (1 vote)",
    "value":"1",
    "percentage":100,
    "is_current_selection":false
  },
  {
    "choice":"KanBan",
    "display_value":"0% (0 votes)",
    "value":0,
    "percentage":0,
    "is_current_selection":false
  }]
}

POST

The implementation of POST verbose is use to vote a choice.
Implements some validation, for example, if user is Allowed to Vote.

Request
curl -d '{"chid":"1"}' -H "Content-Type: application/json" -X POST http://locahost/api/v1/poll/1/vote
Response
{
  "error": false
}

DELETE

The implementation of DELETE verbose is use to cancel a vote of a User.
Implements some validation, for example, if user is Allowed to cancel his vote.

Request

curl -X DELETE http://locahost/api/v1/poll/1

Response
{
  "error": false
}
Supporting organizations: 
Development and maintenance

Project information

Releases