Back to top

Polls

Polls is a simple API allowing consumers to view polls and vote in them. You can view this documentation over at Apiary.

Resource Group

Polls API Root

This resource does not have any attributes. Instead it offers the initial API affordances in the form of the links in the JSON body.

It is recommend to follow the “url” link values, Link or Location headers where applicable to retrieve resources. Instead of constructing your own URLs, to keep your client decoupled from implementation details.

Retrieve the Entry Point
GET/

Example URI

GET http://polls.apiblueprint.org/
Response  200
HideShow
Headers
Content-Type: application/json
Body
{
  "questions_url": "/questions"
}

Question

Resources related to questions in the API.

Question

A Question object has the following attributes:

  • question

  • published_at - An ISO8601 date when the question was published.

  • url

  • choices - An array of Choice objects.

View a Questions Detail
GET/questions/{question_id}

Example URI

GET http://polls.apiblueprint.org/questions/1
URI Parameters
HideShow
question_id
number (required) Example: 1

ID of the Question in form of an integer

Response  200
HideShow
Headers
Content-Type: application/json
Body
{
  "question": "Favourite programming language?",
  "published_at": "2014-11-11T08:40:51.620Z",
  "url": "/questions/1",
  "choices": [
    {
      "choice": "Swift",
      "url": "/questions/1/choices/1",
      "votes": 2048
    },
    {
      "choice": "Python",
      "url": "/questions/1/choices/2",
      "votes": 1024
    },
    {
      "choice": "Objective-C",
      "url": "/questions/1/choices/3",
      "votes": 512
    },
    {
      "choice": "Ruby",
      "url": "/questions/1/choices/4",
      "votes": 256
    }
  ]
}

Choice

Vote on a Choice
POST/questions/{question_id}/choices/{choice_id}

This action allows you to vote on a question’s choice.

Example URI

POST http://polls.apiblueprint.org/questions/1/choices/1
URI Parameters
HideShow
question_id
number (required) Example: 1

ID of the Question in form of an integer

choice_id
number (required) Example: 1

ID of the Choice in form of an integer

Response  201
HideShow
Headers
Location: /questions/1

Questions Collection

List All Questions
GET/questions{?page}

Example URI

GET http://polls.apiblueprint.org/questions?page=1
URI Parameters
HideShow
page
number (optional) Example: 1

The page of questions to return

Response  200
HideShow
Headers
Content-Type: application/json
Link: </questions?page=2>; rel="next"
Body
[
  {
    "question": "Favourite programming language?",
    "published_at": "2014-11-11T08:40:51.620Z",
    "url": "/questions/1",
    "choices": [
      {
        "choice": "Swift",
        "url": "/questions/1/choices/1",
        "votes": 2048
      },
      {
        "choice": "Python",
        "url": "/questions/1/choices/2",
        "votes": 1024
      },
      {
        "choice": "Objective-C",
        "url": "/questions/1/choices/3",
        "votes": 512
      },
      {
        "choice": "Ruby",
        "url": "/questions/1/choices/4",
        "votes": 256
      }
    ]
  }
]

Create a New Question
POST/questions{?page}

You may create your own question using this action. It takes a JSON object containing a question and a collection of answers in the form of choices.

  • question (string) - The question

  • choices (array[string]) - A collection of choices.

Example URI

POST http://polls.apiblueprint.org/questions?page=1
URI Parameters
HideShow
page
number (optional) Example: 1

The page of questions to return

Request
HideShow
Headers
Content-Type: application/json
Body
{
  "question": "Favourite programming language?",
  "choices": [
    "Swift",
    "Python",
    "Objective-C",
    "Ruby"
  ]
}
Response  201
HideShow
Headers
Content-Type: application/json
Location: /questions/2
Body
{
  "question": "Favourite programming language?",
  "published_at": "2014-11-11T08:40:51.620Z",
  "url": "/questions/2",
  "choices": [
    {
      "choice": "Swift",
      "url": "/questions/2/choices/1",
      "votes": 0
    },
    {
      "choice": "Python",
      "url": "/questions/2/choices/2",
      "votes": 0
    },
    {
      "choice": "Objective-C",
      "url": "/questions/2/choices/3",
      "votes": 0
    },
    {
      "choice": "Ruby",
      "url": "/questions/2/choices/4",
      "votes": 0
    }
  ]
}

Questions Collection

Create a New Question1
POST/questions1{?page}

You may create your own question using this action. It takes a JSON object containing a question and a collection of answers in the form of choices.

Example URI

POST http://polls.apiblueprint.org/questions1?page=1
URI Parameters
HideShow
page
number (optional) Example: 1

The page of questions to return

Request
HideShow
Headers
Content-Type: application/json
Body
{
    "question": "Favourite language?"
    "choices": [
        "Swift",
        "Objective-C"
    ]
}
Schema
{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "question": {
      "type": "string"
    },
    "choices": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "minItems": 2
    }
  }
}
Response  200

Generated by aglio on 28 Nov 2017