Skip to content

API: questions

luqiuyuan edited this page Jun 7, 2019 · 1 revision
VERB PATH DESC
GET /questions show all questions
GET /questions/:id show a question
POST /questions create a question
PATCH/PUT questions/:id update a question
DELETE questions/:id destroy a question

GET /questions

response

see view INDEX

statuses and errors

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

GET /questions/:id

response

see view INDEX

statuses and errors

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

POST /questions

request

{
  "question": {
    "title": "You are the apple of my eyes",
    "content": "Really?"
  }
}

validations

  • question (required)
    • title (required, max length 255)
    • content (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": "question:title" }
invalid_field 参数错误 { "code": "invalid_field", "field": "question:title" }

PATCH/PUT /questions/:id

request

{
  "question": {
    "title": "You are the apple of my eyes",
    "content": "Really?"
  }
}

validations

  • question (required)
    • title (required, max length 255)
    • content (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": "question" }
invalid_field 参数错误 { "code": "invalid_field", "field": "question:title" }
not found (404) 未找到

DELETE /questions/:id

response

see view INDEX

statuses and errors

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

Views

SHOW

{
  "question": {
    "id": 1,
    "title": "Why human is born alone?",
    "user_id": 5,
    "created_at": "2016-05-01T23:00:00.000Z",
    "updated_at": "2016-05-01T23:00:00.000Z",
    "number_of_likes": 15,
    "liked": true
  }
}

INDEX

{
  "questions": [
    {
      "id": 1,
      "title": "Why human is born alone?",
      "user_id": 5,
      "created_at": "2016-05-01T23:00:00.000Z",
      "updated_at": "2016-05-01T23:00:00.000Z",
      "number_of_likes": 0,
      "liked": false
    }
  ]
}