Skip to content

Documentation API

Krucksy edited this page Apr 2, 2024 · 47 revisions
GET /api/category/iq
Description Get all categories with the IQ of current User
Result Type JSON
Authentification mandatory? Yes
Controller
Parameters -
Failure cases User is not authentificated - 401

Success response exemple: (keys are category id)
{
"1": {
"category_name": "Animals",
"user_iq": 100
},
"2": {
"category_name": "Brain Teasers",
"user_iq": 100
}
}

GET /api/category/{category_id}/image
Description Get category image
Result Type Image
Authentification mandatory? No
Controller
Parameters -
Failure cases Category doesn't exist - 404

Success response exemple:
return image Success response example:
{
"user_rank": 45,
"user_score": 1000
}

GET /api/question/{category_id}/new
Description Set the current question for the user, and return the question
Result Type JSON
Authentification mandatory? Yes
Controller
Parameters category_id: ID of the question's category
Failure cases User is not authentificated - 401 Category does not exist - 404

Success response example {
"id": 623,
"text": "What is the Yorkshire Terriers average lifespan?\n",
"category": "Animals"
}

GET /api/question/options
Description Get the options for the user's current question
Result Type JSON
Authentification mandatory? Yes
Controller
Parameters -
Failure cases User is not authentificated - 401

Success response example:
{
"question_id":1,
"number_of_options":4,
"options:" {
"234:"the panther",
"432":"the cheetah",
"234":"the jaguar",
"324":"the leopard",
}
}

POST /api/question/new_community
Description add a question to the community category
Result Type JSON
Authentification mandatory? Yes
Controller
Parameters -
Failure cases User is not authentificated - 401

Request body example:
{
"question": "How old is Harry Potter at the beginning of the first book?",
"options": [
"11",
"15",
"He wasn't born"
],
"answer": "1"
}

Success response example: {
"text": "Howfdsfds old is Harry Potter at the beginning of the first book?", "category": "Community" }

POST /api/question/answer_option
Description Send answer to current question, as one of the proposed options
Result Type JSON
Authentification mandatory? Yes
Controller
Parameters -
Failure cases User is not authentificated - 401 User did not ask for options - 403

request body example:
{
"answer":"232"
}

success response examples:
{
"user_is_correct":true,
"right_answer":"1",
"answer_sent":"1"
}
or
{
"user_is_correct":false,
"right_answer":"1",
"answer_sent":"he wasn't born"
}

POST /api/question/answer_text
Description Send answer to current question, as text
Result Type JSON
Authentification mandatory? Yes
Controller
Parameters -
Failure cases User is not authentificated - 401 User already asked for options - 403

Request body example: { "answer":"he wasn't born" }

success response examples:
{
"user_is_correct":true,
"right_answer":"1",
"answer_sent":"1"
}
or
{
"user_is_correct":false,
"right_answer":"1",
"answer_sent":"he wasn't born"
}

GET /api/rank/{category_id}/leaderboard
Description Get best players in category
Result Type JSON
Authentification mandatory? Yes
Controller
Parameters -
Failure cases User is not authentificated - 401 Category does not exist - 404

Success response example:
[
{
"user_id":123,
"user_name":"Strogator",
"user_iq":150 },
{
"user_id":3,
"user_name":"Krucksy",
"user_iq":136 },
...
]

GET /api/rank/{category_id}/user
Description Get user rank and IQ in category
Result Type JSON
Authentification mandatory? Yes
Controller
Parameters -
Failure cases User is not authentificated - 401 Category does not exist - 404

Success response example:
{
"user_rank": 45,
"user_iq": 108
}

GET /api/rank/global_leaderboard
Description Get the 10 global best best players
Result Type JSON
Authentification mandatory? Yes
Controller
Parameters -
Failure cases User is not authentificated - 401

Success response infos:
JSON array are ordered. The first element of the list is the first player, and it then goes in descending order
The array must contains at maximum 10 entry. If there is less than 10 entry, it means that there is less than 10 players in the database.
Score calculation is still not decided, scores in example may not be representative of real data.

Success response example:
[
{
"user_id":123,
"user_name":"Strogator",
"user_score":1890
},
{
"user_id":3,
"user_name":"Krucksy",
"user_score":1800
},
...
]

GET /api/rank/global_user
Description Get the position in leaderboard and score of current user
Result Type JSON
Authentification mandatory? Yes
Controller
Parameters -
Failure cases User is not authentificated - 401
GET /category/{category_id}/user_iq
Description Get user IQ in category
Result Type JSON
Authentification mandatory? Yes
Controller
Parameters -
Failure cases User is not authentificated - 401 Category does not exist - 404

Success response example:
{
"user_iq": 108
}

NON IMPLEMENTE

POST /api/user/login
Description Authentificate user
Result Type -
Authentification mandatory? No
Controller
Parameters -
Failure cases Login credentials unvalid - 401

NON IMPLEMENTE

POST /api/user/register
Description Create new user account
Result Type -
Authentification mandatory? No
Controller
Parameters -
Failure cases Username already taken - 409

NON IMPLEMENTE

GET /api/coffee
Description Brew a coffee
Result Type -
Authentification mandatory? No
Controller
Parameters -
Failure cases The pot is a teapot - 418
Clone this wiki locally