Skip to main content

Submit an answer for one question in a practice session

POST 

/sessions/:session_id/answers

Records the user's answer to a single question. The backend determines correctness server-side -- the client does NOT send is_correct. Per-type validation:

  • multiple-choice -- exact string match between user_answer and the text of the option whose is_correct flag is true. verified: true.
  • true-false -- user_answer MUST be the lowercase string "true" or "false". The backend parses it and compares against the canonical answer derived from the "True" option's is_correct flag. verified: true.
  • freeform -- case-insensitive trimmed string compare against quiz_questions.reference_answer. The response carries verified: false because string-match is not semantic validation.

On a correct answer, the parent session's correct_answers counter is incremented by 1 in the same transaction as the insert.

Authorization: the session must belong to the authenticated user (403 otherwise). Sessions that have already been completed reject submissions with 409 (the SELECT FOR UPDATE on the session row serializes against a concurrent complete-session call).

Duplicate submission protection: the uq_practice_answers_session_question unique constraint catches the case where a question is answered twice in the same session. The service surfaces the unique violation as a typed 400 with details {"question_id": "already answered"}.

No auto-completion: even when this answer is the last unanswered question in the snapshot, the session stays in-progress until the client explicitly calls POST /api/sessions/{session_id}/complete (ASK-140, future).

Request

Responses

Answer recorded with backend-determined correctness.