Skip to content

Question API

corlick98 edited this page Apr 14, 2021 · 15 revisions
QUESTION JSON SCHEMA EXAMPLE

{
      "id": 71,
      "title": "Mock Question 2",
      "text": "",
      "create_date": "2021-04-08T23:04:00Z",
      "last_modify_date": "2021-04-13T17:56:43Z",
      "author": "instructor email: [email protected]",
      "grade_policy": {
        "max_tries": 3,
        "free_tries": 1,
        "penalty_per_try": 10
      },
      "in_quiz": false,
      "course": null,
      "quizzes": [],
      "mark": 500,
      "tags": [
        {
          "id": 4,
          "name": "fun"
        },
        {
          "id": 5,
          "name": "Color"
        }
      ],
      "variables": {
        "type": "script",
        "value": "",
        "language": "sage"
      },
      "responses": [
        {
          "id": 141,
          "index": 0,
          "text": "Enter 'Red'",
          "identifier": "_input",
          "patterntype": "Custom",
          "pattern": "",
          "patternflag": "",
          "patternfeedback": "",
          "question": 71,
          "type": {
            "name": "tree"
          }
        },
        {
          "id": 133,
          "answers": [
            {
              "text": "red",
              "grade": 50,
              "comment": ""
            },
            {
              "text": "Red",
              "grade": 100,
              "comment": ""
            },
            {
              "text": "Blue",
              "grade": 0,
              "comment": ""
            }
          ],
          "index": 1,
          "text": "Select 'Red'",
          "identifier": "_multChoice1",
          "mark": 100,
          "question": 71,
          "type": {
            "name": "multiple",
            "single": true,
            "dropdown": true
          }
        },
        {
          "id": 134,
          "answers": [
            {
              "text": "red",
              "grade": 50,
              "comment": ""
            },
            {
              "text": "Red",
              "grade": 100,
              "comment": ""
            },
            {
              "text": "Blue",
              "grade": 0,
              "comment": ""
            }
          ],
          "index": 2,
          "text": "Select 'Red'",
          "identifier": "_multChoice2",
          "mark": 100,
          "question": 71,
          "type": {
            "name": "multiple",
            "single": true,
            "dropdown": false
          }
        },
        {
          "id": 136,
          "answers": [
            {
              "text": "red",
              "grade": 50,
              "comment": ""
            },
            {
              "text": "Red",
              "grade": 50,
              "comment": ""
            },
            {
              "text": "Blue",
              "grade": 0,
              "comment": ""
            }
          ],
          "index": 3,
          "text": "Select all 'red'",
          "identifier": "_multChoice3",
          "mark": 100,
          "question": 71,
          "type": {
            "name": "multiple",
            "single": false,
            "dropdown": true
          }
        },
        {
          "id": 137,
          "answers": [
            {
              "text": "red",
              "grade": 50,
              "comment": "feedback1"
            },
            {
              "text": "Red",
              "grade": 50,
              "comment": "feedback2"
            },
            {
              "text": "Blue",
              "grade": -50,
              "comment": ""
            }
          ],
          "index": 4,
          "text": "Select all 'red'",
          "identifier": "_multChoice4",
          "mark": 100,
          "question": 71,
          "type": {
            "name": "multiple",
            "single": false,
            "dropdown": false
          }
        }
      ],
      "tree": {
        "name": "tree",
        "type": -1,
        "policy": "sum",
        "children": [
          {
            "bool": true,
            "type": 1,
            "title": "_input == \"Red\"",
            "policy": {
              "true": "sum",
              "false": "sum"
            },
            "children": [
              {
                "bool": true,
                "type": 0,
                "score": 100,
                "title": "Correct Answer",
                "policy": {
                  "true": "sum",
                  "false": "sum"
                },
                "feedback": "You got it right!"
              },
              {
                "bool": false,
                "type": 1,
                "title": "_input == \"red\"",
                "policy": {
                  "true": "sum",
                  "false": "sum"
                },
                "children": [
                  {
                    "bool": true,
                    "type": 0,
                    "score": 50,
                    "title": "spelling mistake",
                    "policy": {
                      "true": "sum",
                      "false": "sum"
                    },
                    "feedback": "Almost. Check your capitalization."
                  }
                ],
                "feedback": {
                  "error": "An Error occurred during execution."
                }
              }
            ],
            "feedback": {
              "error": "An Error occurred during execution."
            }
          },
          {
            "bool": true,
            "type": 2,
            "title": "Score mult 1",
            "policy": {
              "true": "sum",
              "false": "sum"
            },
            "identifier": "_multChoice1"
          },
          {
            "bool": true,
            "type": 2,
            "title": "score mult 2",
            "policy": {
              "true": "sum",
              "false": "sum"
            },
            "identifier": "_multChoice2"
          },
          {
            "bool": true,
            "type": 1,
            "title": "len(_multChoice3) != 3",
            "policy": {
              "true": "sum",
              "false": "sum"
            },
            "children": [
              {
                "bool": true,
                "type": 2,
                "title": "score mult 4",
                "policy": {
                  "true": "sum",
                  "false": "sum"
                },
                "identifier": "_multChoice3"
              }
            ],
            "feedback": {
              "error": "An Error occurred during execution.",
              "false": "You cannot select all answers."
            }
          },
          {
            "bool": true,
            "type": 1,
            "title": "len(_multChoice4) != 3",
            "policy": {
              "true": "sum",
              "false": "sum"
            },
            "children": [
              {
                "bool": true,
                "type": 2,
                "title": "score mult 5",
                "policy": {
                  "true": "sum",
                  "false": "sum"
                },
                "identifier": "_multChoice4"
              }
            ],
            "feedback": {
              "error": "An Error occurred during execution.",
              "false": "You cannot select all answers."
            }
          }
        ]
      },
}
GET api/questions

get all questions

POST api/questions

create a question

{
  "title": "Mock Question 2",
  "text": "Some interesting multiple choice questions.",
  "tags": [
    {
      "name": "fun"
    },
    {
      "name": "color"
    }
  ],
  "responses": [
    {
      "type": {
        "name": "multiple",
        "single": true,
        "dropdown": false
      },
      "text": "Select 'Red'",
      "answers": [
        {
          "text": "Blue",
          "grade": 0
        },
        {
          "text": "Red",
          "grade": 100
        },
        {
          "text": "red",
          "grade": 50
        }
      ]
    },
    {
      "type": {
        "name": "multiple",
        "single": false,
        "dropdown": false
      },
      "text": "Select red color",
      "answers": [
        {
          "text": "Blue",
          "grade": -50
        },
        {
          "text": "Red",
          "grade": 50
        },
        {
          "text": "red",
          "grade": 50
        }
      ]
    },
    {
      "type": {
        "name": "multiple",
        "single": false,
        "dropdown": true
      },
      "text": "Select red color",
      "answers": [
        {
          "text": "Blue",
          "grade": -50
        },
        {
          "text": "Red",
          "grade": 50
        },
        {
          "text": "red",
          "grade": 50
        }
      ]
    }
  ]
}
GET /api/questions/{id}

get a questions by id

PATCH /api/questions/{id}

update a question by id

request.body is same as POST /api/questions

NOTE: allow a complete or partial replacement of a question 👍

HINT

You can always update the whole question byPATCH. Since PATCH is a partially updating method, If you want to set some field as null, you always need to provide null value. For example, you want to reset question.responses as [ ] you need to

{
...
"responses" : [ ]
...
}

NOTE: you can partially update question. For example, you can

{
"title": "Mock Question 2 new",
}

to change the title only.

BUT for the nested field like TAG, RESPONSE You can partially update the whole RESPONSE field but not a specific sub-field in RESPONSE For example, currently question.tags has two TAG, one is fun another is color. You can

  "tags": [
    {
      "name": "fun new"
    },
    {
      "name": "color"
    }
  ],

to partial update whole question.tags only. 👍

But you can't partially update the tag fun to fun new, even you give the id (id will be ignored)

  "tags": [
    {
     "id": 1,
      "name": "fun new"
    }
  ],

This will make question.tags only contains one tag 👎

DELETE /api/questions/{id}

delete a question by id

TEMPLATE

METHOD URI

Clone this wiki locally