API: questions - luqiuyuan/reactjs_course_2019_summer GitHub Wiki
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
}
]
}