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

Alternative

Create Alternative

Request:

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

Request's payload:

{
  "value" : "answer 1"
}

Curl:

curl -i -H "Content-Type:application/json" -H "Accept:application/hal+json" -X POST http://127.0.0.1:8080/polls/1/alternatives -d '{ "value" : "answer 1" }'

Response:

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

{
  "id" : 1,
  "value" : "answer 1",
  "voteCount" : 5,
  "_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"
    }
  }
}

Retrieve Alternative

Request:

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

Curl:

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

Response:

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

{
  "id" : 1,
  "value" : "answer 1",
  "voteCount" : 2,
  "_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"
    }
  }
}
Clone this wiki locally