Skip to content

Questions API

Kerry Gougeon Ducharme edited this page Feb 19, 2018 · 15 revisions

Questions

Types returned question and questions

The following is a question entity it returns info on a question. The answers property only appears when querying one question.

{"id": 100, "title": 'How does Questions API work?', "text": 'I want to know!', "register_date": '2017-02-15', "engineer":'software', "closed": false, "user_id", 1, "downs": 99, "ups": 10000, "answers": [<Answer1>,<Answer2>,...]}

The answer structure mentioned above is like this. {"id": 190, "text": 'Read this doc', "register_date": '2017-02-15', "engineer":'software', "accepted": false, "question_id": 100, "user_id", 3, "downs": 999, "ups": 900}

When querying multiple questions (for example by user_id or by engineer) the structure will be an array of questions without answers.

{"id": 100, "title": 'How does Questions API work?', "text": 'I want to know!', ...},
{"id": 101, "title": 'Questions in a list?', "text": 'Same as title', ...},
{"id": 102, "title": 'I can question?', "text": 'blah blah blah', ...}
]```

For example in a programming language like JavaScript or Python if the variable `questionsArray` contained a questions object we might access the text the first question:

// JS questionsArray[0].text

Python:

questionsArray[0]['text']

In this case it will return 'I want to know!'. Remember these objects are JSON. In Python they map to `dict` and in JavaScript they map to `object`.

#### Question routes

`route: /api/qa/questions/`

Note below that * indicates the data is optional. Also note that in a GET request the expected data should be in the URL. Using GET below if you send `question_id` a single `question` will be returned, all other combinations will return a `questions` object. `sort` can be any string of the keys of the `question` object, example `sort="ups"`.



| HTTP Requests 	| Description of Action  | Expected Data from Front-End	| Response (JSON)                	|
|:-------------:	|----------------------- |------------------------------|--------------------------------	|
| POST          	| Creates a new question.    | title, text, user_id, engineer  | success, status, message, question      	|
| GET           	| Get question.         | *user_id, *question_id, *engineer, *sort  | success, status, message, *question, *questions	|