The Exams API provides comprehensive functionality for managing student examinations, including:
http://localhost:3000/api/v1/exams
Generates a new exam for a student with a mix of MCQ and True/False questions.
POST /api/v1/exams/generate
Request Body:
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
courseId |
integer | β | - | Course ID for which exam is generated |
studentId |
integer | β | - | Student ID taking the exam |
mcqCount |
integer | β | 5 | Number of MCQ questions (max 10 total) |
tfCount |
integer | β | 5 | Number of True/False questions (auto-calculated as 10 - mcqCount) |
Example Request:
{
"courseId": 11,
"studentId": 1,
"mcqCount": 6,
"tfCount": 4
}
Success Response (200):
{
"success": true,
"data": {
"examDetails": {
"Status": 1,
"StatusMessage": "Exam generated successfully",
"ExamID": 101,
"StudentID": 1
},
"questions": [
{
"questionid": 1,
"questiontext": "What is JavaScript?",
"questiontype": "MCQ",
"degree": 10,
"choicelabel": "A",
"choicetext": "A programming language"
},
{
"questionid": 1,
"questiontext": "What is JavaScript?",
"questiontype": "MCQ",
"degree": 10,
"choicelabel": "B",
"choicetext": "A markup language"
}
],
"ExamStartedAt": "2026-01-23T10:30:00.000Z"
}
}
Error Response (500):
{
"success": false,
"data": "Server Error",
"error": "Detailed error message"
}
Submits student answers for an exam and returns the calculated grade.
POST /api/v1/exams/submit
Request Body:
| Field | Type | Required | Description |
|---|---|---|---|
examID |
integer | β | Exam ID to submit answers for |
studentID |
integer | β | Student ID submitting the answers |
answers |
string | β | Comma-separated answer labels (e.g., βA,B,C,True,False,A,B,True,C,Aβ) |
Example Request:
{
"examID": 101,
"studentID": 1,
"answers": "A,B,C,T,F,A,B,T,C,A"
}
Success Response (200) - On Time Submission:
{
"success": true,
"data": {
"message": "Answers submitted successfully",
"grade": 85
}
}
Success Response (200) - Time Exceeded:
{
"success": true,
"data": {
"message": "Exam time exceeded. Answers submitted as no answers.",
"grade": 0
}
}
Error Response (400):
{
"success": false,
"data": [
{
"msg": "examID is required",
"param": "examID",
"location": "body"
}
]
}
Error Response (500):
{
"success": false,
"data": {
"message": "Server Error",
"error": "Detailed error message"
}
}
Retrieves detailed exam review including questions, choices, student answers, and correct answers.
GET /api/v1/exams/review/:examID/:studentID
Path Parameters:
| Parameter | Type | Description |
|---|---|---|
examID |
integer | Exam ID to review |
studentID |
integer | Student ID who took the exam |
Example Request:
GET /api/v1/exams/review/101/1
Success Response (200):
{
"success": true,
"data": [
{
"questionid": 1,
"questiontext": "What is JavaScript?",
"selectedLabel": "A",
"correctLabel": "A",
"mark": 10,
"choices": [
{
"label": "A",
"text": "A programming language"
},
{
"label": "B",
"text": "A markup language"
},
{
"label": "C",
"text": "A database"
},
{
"label": "D",
"text": "An operating system"
}
]
},
{
"questionid": 2,
"questiontext": "JavaScript is case-sensitive.",
"selectedLabel": "T",
"correctLabel": "T",
"mark": 10,
"choices": [
{
"label": "T",
"text": "T"
},
{
"label": "F",
"text": "F"
}
]
}
]
}
Error Response (500):
{
"success": false,
"error": "Detailed error message"
}
Retrieves all exams taken by a specific student.
GET /api/v1/exams/:studentID
Path Parameters:
| Parameter | Type | Description |
|---|---|---|
studentID |
integer | Student ID to get exam history for |
Example Request:
GET /api/v1/exams/1
Success Response (200):
{
"success": true,
"data": [
{
"examid": 101,
"courseid": 11,
"coursename": "JavaScript Fundamentals",
"grade": 85,
"examdate": "2026-01-23T10:30:00.000Z",
"ExamStartedAt": "2026-01-23T10:30:00.000Z"
},
{
"examid": 102,
"courseid": 12,
"coursename": "React.js",
"grade": 90,
"examdate": "2026-01-22T14:00:00.000Z",
"ExamStartedAt": "2026-01-22T14:00:00.000Z"
}
]
}
Error Response (500):
{
"success": false,
"error": "Detailed error message"
}
Checks the current status of an ongoing exam and returns remaining time.
GET /api/v1/exams/:examId/:studentID
Path Parameters:
| Parameter | Type | Description |
|---|---|---|
examId |
integer | Exam ID to check status for |
studentID |
integer | Student ID taking the exam |
Example Request:
GET /api/v1/exams/101/1
Success Response (200) - Active Exam:
{
"success": true,
"status": "ACTIVE",
"remainingMinutes": "12.45"
}
Error Response (400) - Already Submitted:
{
"success": false,
"status": "SUBMITTED",
"message": "Exam already submitted"
}
Error Response (400) - Time Expired:
{
"success": false,
"status": "TIMEOUT",
"message": "Exam time has expired"
}
Error Response (404) - Exam Not Found:
{
"success": false,
"message": "Exam not found"
}
Error Response (500):
{
"success": false,
"error": "Detailed error message"
}
The Exams API uses the following SQL Server stored procedures:
| Procedure | Purpose | Parameters |
|---|---|---|
generate_exam |
Generate a new exam with random questions | @courseId, @studentId, @mcqCount, @tfCount |
getexamquestions |
Retrieve questions for a generated exam | @examid |
exam_answers |
Store studentβs answers | @examID, @studentID, @ans1 through @ans10 |
exam_correction |
Calculate and store exam grade | @examID, @studentID |
GetExamReview_Split |
Get detailed exam review with answers | @examID, @studentID |
GetStudentExamsHistory |
Get all exams for a student | @studentID |
| Code | Status | Description |
|---|---|---|
200 |
OK | Request successful |
400 |
Bad Request | Validation error, exam already submitted, or time expired |
404 |
Not Found | Exam not found |
500 |
Internal Server Error | Server-side or database error |
| Status | Description |
|---|---|
ACTIVE |
Exam is currently in progress |
SUBMITTED |
Exam has already been submitted and graded |
TIMEOUT |
Exam time limit (15 minutes) has expired |
ExamIDExamStartedAt timestamp is recorded for time trackingnullnull| Method | Endpoint | Description |
|---|---|---|
POST |
/api/v1/exams/generate |
Generate new exam |
POST |
/api/v1/exams/submit |
Submit exam answers |
GET |
/api/v1/exams/review/:examID/:studentID |
Get exam review |
GET |
/api/v1/exams/:studentID |
Get studentβs exam history |
GET |
/api/v1/exams/:examId/:studentID |
Check exam status |
| Field | Validation Rules |
|ββ-|ββββββ|
| courseId | Required, must be positive integer |
| studentId | Required, must be positive integer |
| mcqCount | Optional, integer between 0-10 |
| tfCount | Optional, integer between 0-10 |
| Field | Validation Rules |
|ββ-|ββββββ|
| examID | Required, must be positive integer |
| studentID | Required, must be positive integer |
| answers | Required, comma-separated string |
| Field | Location | Validation Rules |
|ββ-|βββ-|ββββββ|
| examID | params | Required, must be positive integer |
| studentID | params | Required, must be positive integer |