@fellendorf/api-quiz-questions-module
v1.4.4
Published
NestJS module containing "questions" REST API endpoints for "quiz" application
Downloads
1,754
Readme
Description
NestJS module containing Questions REST API endpoints for Quiz application.
Table of Contents:
- Retrieve a list of quiz questions
- Retrieve a list of quiz topics
- Create a new quiz question
- Update a quiz question
- Delete a quiz question by id
- Create new quiz questions
API endpoints
Retrieve a list of quiz questions
${\textsf{\color{lightgreen}GET}}$ https://{host}/quiz/questions
QUERY PARAMS
| Param | Type | Required | Description | Example | | -------- | ------ | -------- | ----------------------------------- | ------- | | topics[] | string | false | The topics to filter questions by | HTML | | count | number | false | The number of questions to retrieve | 10 |
RESPONSE BODY
[
{
topic: string;
text: string;
code?: {
text: string;
language: 'typescript' | 'javascript' | 'html' | 'css';
}
options: string[];
answer: {
index: number;
explanation?: string;
};
meta?: {
reviewed?: boolean;
difficult?: 'easy' | 'medium' | 'hard';
}
}
]
[!TIP] To filter by multiple topics, use a few "topics[]" query parameters. For example:
/quiz/questions?topics[]=HTML&topics[]=CSS
Retrieve a list of quiz topics
${\textsf{\color{lightgreen}GET}}$ https://{host}/quiz/topics
RESPONSE BODY
[
{
name: string;
questionCount: number;
}
]
Create a new quiz question
${\textsf{\color{orange}POST}}$ https://{host}/quiz/question
REQUEST BODY
{
topic: string;
text: string;
code?: {
text: string;
language: 'typescript' | 'javascript' | 'html' | 'css';
}
options: string[];
answer: {
index: number;
explanation?: string;
};
meta?: {
reviewed?: boolean;
difficult?: 'easy' | 'medium' | 'hard';
}
}
Update a quiz question
${\textsf{\color{blue}PUT}}$ https://{host}/quiz/question
REQUEST BODY
{
_id: string;
topic: string;
text: string;
code?: {
text: string;
language: 'typescript' | 'javascript' | 'html' | 'css';
}
options: string[];
answer: {
index: number;
explanation?: string;
};
meta?: {
reviewed?: boolean;
difficult?: 'easy' | 'medium' | 'hard';
}
}
Delete a quiz question by id
${\textsf{\color{red}DELETE}}$ https://{host}/quiz/question
QUERY PARAMS
| Param | Type | Required | Description | Example | | ----- | ------ | -------- | --------------------- | ------------------------ | | id | string | true | Question ID to delete | 671438511204ca5ad9df5366 |
Create new quiz questions
${\textsf{\color{orange}POST}}$ https://{host}/quiz/questions
REQUEST BODY
[
{
topic: string;
text: string;
code?: {
text: string;
language: 'typescript' | 'javascript' | 'html' | 'css';
}
options: string[];
answer: {
index: number;
explanation?: string;
};
meta?: {
reviewed?: boolean;
difficult?: 'easy' | 'medium' | 'hard';
}
}
]
How to use
Install the package to the main NestJS application and add it to the main module imports:
import { QuestionsModule } from '@fellendorf/api-quiz-questions-module';
@Module({
imports: [QuestionsModule],
controllers: [],
providers: [],
})
[!IMPORTANT] Main application must be connected to the MongoDB database.
How to develop
Repository contains an app module (src/_dev-only
) just for development purposes. Additionally:
- command
npm run build
is set to use this main module to develop the "Questions" module; - the folder containing the main module will not be included in the npm package (see
.npmignore
file)
[!NOTE] Using
npm link
command orfile://...
path in pacakge.json brings some bugs.
App TODO:
- TESTS