Skip to content
nvasilev edited this page Nov 13, 2014 · 1 revision

Poll

Create Poll

Request:

POST http://127.0.0.1:8080/polls
Content-Type:application/json
Accept:application/hal+json

Request's Payload:

{
	"topic": "poll 1"
}

Response: 201 CREATED

{
    "id": 1,
    "topic": "poll 1",
    "_links": {
        "self": {
            "href": "http://127.0.0.1:8080/polls/1"
        }
    }
}

Retrieve Poll

Request:

GET http://127.0.0.1:8080/polls/1
Accept:application/hal+json

Curl:

curl -i -H Accept:application/hal+json" -X GET http://127.0.0.1:8080/polls/1

Response:

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: application/hal+json
Transfer-Encoding: chunked

{
  "id" : 1,
  "topic" : "poll topic",
  "_links" : {
    "self" : {
      "href" : "http://127.0.0.1:8080/polls/1"
    },
    "alternatives" : [ {
      "href" : "http://127.0.0.1:8080/polls/1/alternatives/1"
    }, {
      "href" : "http://127.0.0.1:8080/polls/1/alternatives/2"
    }, {
      "href" : "http://127.0.0.1:8080/polls/1/alternatives/3"
    } ]
  },
  "_embedded" : {
    "alternatives" : [ {
      "id" : 1,
      "value" : "answer 1",
      "voteCount" : 1,
      "_links" : {
        "self" : {
          "href" : "http://127.0.0.1:8080/polls/1/alternatives/1"
        },
        "votesCount" : {
          "href" : "http://127.0.0.1:8080/polls/1/alternatives/1/votes/count"
        },
        "alternatives" : {
          "href" : "http://127.0.0.1:8080/polls/1/alternatives"
        },
        "poll" : {
          "href" : "http://127.0.0.1:8080/polls/1"
        }
      }
    }, {
      "id" : 2,
      "value" : "answer 2",
      "voteCount" : 3,
      "_links" : {
        "self" : {
          "href" : "http://127.0.0.1:8080/polls/1/alternatives/2"
        },
        "votesCount" : {
          "href" : "http://127.0.0.1:8080/polls/1/alternatives/2/votes/count"
        },
        "alternatives" : {
          "href" : "http://127.0.0.1:8080/polls/1/alternatives"
        },
        "poll" : {
          "href" : "http://127.0.0.1:8080/polls/1"
        }
      }
    }, {
      "id" : 3,
      "value" : "answer 3",
      "voteCount" : 2,
      "_links" : {
        "self" : {
          "href" : "http://127.0.0.1:8080/polls/1/alternatives/3"
        },
        "votesCount" : {
          "href" : "http://127.0.0.1:8080/polls/1/alternatives/3/votes/count"
        },
        "alternatives" : {
          "href" : "http://127.0.0.1:8080/polls/1/alternatives"
        },
        "poll" : {
          "href" : "http://127.0.0.1:8080/polls/1"
        }
      }
    } ]
  }
}

Remove Poll

Request:

DELETE http://127.0.0.1:8080/polls/1

Curl:

curl -i -X DELETE http://127.0.0.1:8080/polls/1

Response:

HTTP/1.1 204 No Content
Server: Apache-Coyote/1.1
Clone this wiki locally