-
Notifications
You must be signed in to change notification settings - Fork 0
API Docs
To create a new user you will have to create a new POST
request to the following URL: https://project-run.herokuapp.com/users
.
The body of the request should contain the name, email and password.
A sample JSON of the request is:
{
"user":{
"name":"John Doe",
"email":"[email protected]",
"password":"dkjIUm21"
}
}
The response will be a JSON again. A sample is provided below:
{
"id": 4,
"name": "John Doe",
"email": "[email protected]",
"password_digest": "$2a$10$XtDtrOH2Pq0fV/g60yNQF.3jafd6I/TX8KeDzL94onQpbCIc53i.2",
"created_at": "2017-02-21T20:06:44.583Z",
"updated_at": "2017-02-21T20:06:44.583Z"
}
We use JWT for authentication
POST
request to https://project-run.herokuapp.com/user_token
.
The response will be a JSON again. A sample is provided below:
{
"jwt": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE0ODc3OTcwMDksInN1YiI6MX0.yNXQ5uS2-vx1jIgYD60uNPkZk-qkAndZlBRTocvoAPM"
}
You need to send the JWT token as an Authentication
header as following Bearer jwt_token
.
Example for the JWT from the last response
Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE0ODc3OTcwMDksInN1YiI6MX0.yNXQ5uS2-vx1jIgYD60uNPkZk-qkAndZlBRTocvoAPM
(more details here https://jwt.io/introduction/)
Example authentication route:
GET
request to https://project-run.herokuapp.com/test
Will return 401
status if Unauthorised
, otherwise 200 with a success status
POST
request to https://project-run.herokuapp.com/quizzes
.
{
"id": 6,
"title": "My quiz",
"questions": [
{
"id": 10,
"question": "Question 1",
"type": "multiple_choice",
"answers": [
{
"id": 22,
"answer": "Answer 5"
},
{
"id": 21,
"answer": "Answer 4"
},
{
"id": 20,
"answer": "Answer 3"
},
{
"id": 19,
"answer": "Answer 2"
},
{
"id": 18,
"answer": "Answer 1"
}
]
},
{
"id": 11,
"question": "Question 1",
"type": "single_choice",
"answers": [
{
"id": 24,
"answer": "Answer 2"
},
{
"id": 23,
"answer": "Answer 1"
}
]
},
{
"id": 12,
"question": "Question 2",
"left": [
{
"id": "WoW0nS0", // Unique ID to be used by the front end
"answer": "left 1"
},
{
"id": "yjriFaM",
"answer": "left 2"
}
],
"right": [
{
"id": "QSpKSFs",
"answer": "right 1"
},
{
"id": "sU5ccVM",
"answer": "right 2"
}
],
"type": "match"
}
]
}
GET
request to https://project-run.herokuapp.com/quizzes/:id
. You can also get all the quizzes available by making a GET
request to https://project-run.herokuapp.com/quizzes/
.
URL: https://project-run.herokuapp.com/quizzes/6
.
Response:
{
"id": 6,
"title": "My quiz",
"questions": [
{
"id": 10,
"question": "Question 1",
"type": "multiple_choice",
"answers": [
{
"id": 22,
"answer": "Answer 5"
},
{
"id": 21,
"answer": "Answer 4"
},
{
"id": 20,
"answer": "Answer 3"
},
{
"id": 19,
"answer": "Answer 2"
},
{
"id": 18,
"answer": "Answer 1"
}
]
},
{
"id": 11,
"question": "Question 1",
"type": "single_choice",
"answers": [
{
"id": 24,
"answer": "Answer 2"
},
{
"id": 23,
"answer": "Answer 1"
}
]
},
{
"id": 12,
"question": "Question 2",
"left": [
{
"id": "WoW0nS0",
"answer": "left 1"
},
{
"id": "yjriFaM",
"answer": "left 2"
}
],
"right": [
{
"id": "QSpKSFs",
"answer": "right 1"
},
{
"id": "sU5ccVM",
"answer": "right 2"
}
],
"type": "match"
}
]
}
POST
request to https://project-run.herokuapp.com/quiz/:id/check
Sample JSON request
{
"questions":[
// single_choice
{
"id": 11, // id of the question
"answer_id": 8
},
// match
{
"id": 12,
"pairs":[
{
"left_choice_id": sU5ccVM,
"right_choice_id": WoW0nS0
},
{
"left_choice_id": yjriFaM,
"right_choice_id": sU5ccVM
}
]
},
// multiple_choice
{
"id":15,
"answer_ids":[
18,
19
]
}
]
}
And a sample response:
[
{
"id": 144,
"correct": false,
"correct_answer": 143
},
{
"id": 145,
"correct": true,
"correct_answers": [
145
]
},
{
"id": 146,
"correct": true,
"correct_pairs": [
{
"left_choice_id": "nxY42Io",
"right_choice_id": "pQgsn1k"
},
{
"left_choice_id": "QszYLpY",
"right_choice_id": "iCU32PE"
},
{
"left_choice_id": "cPxptoc",
"right_choice_id": "eLquggI"
}
]
}
]