Practice API - masai-oss/Masai_Refresh Wiki

Get all available topics

GET /api/practice/topics

PARAMS

RESPONSE

Success (Status code: 200)

{
    "error": false,
    "data": [
        {
            "_id": "60bc997c946b8458d607d9d2",
            "name": "JAVASCRIPT",
            "icon": "2021-04-02T09:36:50.961Zjavascript.svg",
            "total_questions": 420
        },
        {
            "_id": "60bc99c02fa23a596f1d69d1",
            "name": "REACT",
            "icon": "2021-04-02T08:01:56.310Zreact.svg",
            "total_questions": 327
        }
    ]
}

Failure (Status Code: 500)

{
   "error" : true,
   "message" : "Something went wrong",
   "reason" : err
}

Start Practice

POST /api/practice/create

PARAMS

{
   "topic_id" : "605260bac9992fec733acc3f",
   "size" : 15   // Optional, if not passed it takes 5 by default
}

RESPONSE

Success: (Status Code: 200)

{
    "error": false,
    "questions": [
        "60ba55d4e3c5c4050d2a5e24",
        "60ba55d4e3c5c4050d2a5c86",
        "60ba55d4e3c5c4050d2a5d55",
        "60ba55d4e3c5c4050d2a5d04",
        "60ba55d4e3c5c4050d2a5d30"
    ]
}

Failure:

{
    "error": true,
    "message": "Send a topic id"
}
{
    "error": true,
    "message": "Invalid topic id"
}
{
    "error": true,
    "message": "No such topic id"
}
{
   "error" : true,
   "message" : "Something went wrong",
   "reason" : err
}

Get Question

POST /api/practice/question

PARAMS

{
    "topic_id" : "605260bac9992fec733acc3f",
    "question_id" : "60ba55d4e3c5c4050d2a5e15"
}

RESPONSE

Success (Status code: 200)

{
    "error": false,
    "data": {
        "question_id": "60ba55d4e3c5c4050d2a5e15",
        "source": "https://github.com/sudheerj/reactjs-interview-questions",
        "statement": "What is an observable",
        "explanation": "N/A",
        "answer": "An Observable is basically a function that can return a stream of values either synchronously or asynchronously to an observer over time. The consumer can get the value by calling `subscribe()` method. Let's look at a simple example of an Observable\n\n    import { Observable } from \"rxjs\";\n    \n    const observable = new Observable((observer) => {\n      setTimeout(() => {\n        observer.next(\"Message from a Observable!\");\n      }, 3000);\n    });\n    \n    observable.subscribe((value) => console.log(value));\n    \n\n**Note:** Observables are not part of the JavaScript language yet but they are being proposed to be added to the language",
        "likes": 0,                      // total likes for the question
        "like_flag": false,              // flag to indicate whether user had already liked it or not
        "bookmark_flag": false           // flag to indicate whether user had already bookmarked it or not 
    }
}

Failure

{
    "error": true,
    "message": "Send both topic and question id"
}
{
    "error": true,
    "message": "Invalid topic or question id"
}
{
    "error": true,
    "message": "No such topic or question id"
}
{
   "error" : true,
   "message" : "Something went wrong",
   "reason" : err
}

Add or remove questions from bookmark

(Note: If the question is already bookmarked, it removes the question from bookmark else it adds to bookmark)

POST /api/practice/question_bookmark

PARAMS

{
    "question_id" : "60ba55d4e3c5c4050d2a5d92"
}

RESPONSE

Success (Status code: 200)

{
    "error": false,
    "bookmark_flag": false,
    "message": "Action successful"
}

Failure

{
    "error": true,
    "message": "Send a question id"
}
{
    "error": true,
    "message": "Invalid question id"
}
{
    "error": true,
    "message": "No such question id"
}
{
   "error" : true,
   "message" : "Something went wrong",
   "reason" : err
}

Like or dislike a question

(Note: If the question is already liked, it dislikes, else it likes the question)

POST /api/practice/question_like

PARAMS

{
    "question_id" : "60ba55d4e3c5c4050d2a5e15"
}

RESPONSE

Success (Status code: 200)

{
    "error": false,
    "like_flag": true,
    "message": "Action successful"
}

Failure

{
    "error": true,
    "message": "Send a question id"
}
{
    "error": true,
    "message": "Invalid question id"
}
{
    "error": true,
    "message": "No such question id"
}
{
   "error" : true,
   "message" : "Something went wrong",
   "reason" : err
}

Report question

(Note: A user can report a question only once)

POST /api/practice/report/:question_id

PARAMS

{
    reason: ["Question Unclear", "Insufficient Data", "Explanation not clear", "Others"]       // length : min 1, max 4,
    description: "Lorem ipsum, Lorem ipsum"                                                    // length : min 1, max: 255
}

RESPONSE

Success

    { 
       error: false, 
       message: "Question reported successfully"
    }
    { 
       error: false, 
       message: "You already reported the question"
    }

Failure

{
    "error": true,
    "message": error         // relevant message explaining the error
}
{
    "error": true,
    "message": "Invalid question id"
}
{
    "error": true,
    "message": "No such question id"
}
    {
      error: true,
      message: "Something went wrong",
      reason: err,
    }