Skip to content

API: answers

luqiuyuan edited this page Dec 29, 2020 · 2 revisions
VERB PATH DESC
GET /questions/:id/answers get answers of a question
GET /answers/:id show an answer
POST /questions/:id/answers create an answer of a question
PATCH/PUT answers/:id update an answer
DELETE answers/:id destroy an answer

GET /questions/:id/answers

response

see view INDEX

statuses and errors

STATUS ERROR TYPE DESC EXAMPLE
ok (200) 创建成功
not found (404) 未找到

GET /answers/:id

response

see view INDEX

statuses and errors

STATUS ERROR TYPE DESC EXAMPLE
ok (200) 创建成功
not found (404) 未找到

POST /questions/:id/answers

request

{
  "answer": {
    "content": "Dream it possible"
  }
}

validations

  • answer (required)
    • content (required, max length 65535)

response

see view SHOW

statuses and errors

STATUS ERROR TYPE DESC EXAMPLE
created (201) 创建成功
bad request (400) missing_field 缺少参数 { "code": "missing_field", "field": "answer:content" }
invalid_field 参数错误 { "code": "invalid_field", "field": "answer:content" }

PATCH/PUT /answers/:id

request

{
  "answer": {
    "content": "You are the apple of my eyes",
  }
}

validations

  • answer (required)
    • content (required, max length 65535)

response

see view SHOW

statuses and errors

STATUS ERROR TYPE DESC EXAMPLE
ok (200) 成功
bad request (400) missing_field 缺少参数 { "code": "missing_field", "field": "answer" }
invalid_field 参数错误 { "code": "invalid_field", "field": "answer:content" }
not found (404) 未找到

DELETE /answers/:id

response

see view INDEX

statuses and errors

STATUS ERROR TYPE DESC EXAMPLE
ok (200) 成功
not found (404) 未找到

Views

SHOW

{
  "answer": {
    "id": 13579,
    "content": "Dream it possible",
    "question_id": 123,
    "user_id": 2345,
    "created_at": "2016-05-01T23:00:00.000Z",
    "updated_at": "2016-05-01T23:00:00.000Z",
    "number_of_likes": 15,
    "liked": true
  }
}

INDEX

{
  "answers": [
    {
      "id": 13579,
      "content": "Dream it possible",
      "question_id": 953,
      "user_id": 2345,
      "created_at": "2016-05-01T23:00:00.000Z",
      "updated_at": "2016-05-01T23:00:00.000Z",
      "number_of_likes": 0,
      "liked": false
    }
  ]
}