-
Notifications
You must be signed in to change notification settings - Fork 4
REST API Documentation
- Getting a single question
- Getting a list of questions
- Saving a question in the database
- Editing a question in the database
- Deleting a question in the database
- Getting a list of answers for a question
- Saving an answer in the database
- Editing an answer in the database
- Deleting an answer in the database
- Voting for an answer
- Voting for a question
- Registering a user
- Getting information about registered user
- Modifying information of the registered user
- Getting information about a user by username
- Searching for a question
- Getting a list of questions asked and answered by user
- Getting a list jobs posted by a user
- Applying for a job
You will find all information about the REST API calls in this section.
Returns a json object of a single question.
/api/question/:id/
GET
id = Integer
{ id: Integer,question_head: String, question_text: String, date_created: String, user_id: { username: String } }
Returns a json object of a list of questions. By default this list is sorted in descending order by date created and it limits to 10 questions at most.
/api/question/
GET
order = {asc, desc}
limit = Integer
{
question_list: [{
id: int,
question_text: String,
question_head: String
date_created: String,
user_id: {
username: String
},
points: Integer
}, ...]
}
/api/question/?limit=10&order=desc
/api/question/
POST
question_head = String
question_text = String
It saves the question in the database and it returns the id of the newly created question in the form of:
{ id: int }
/api/question/
PUT
q_id = Integer question_head = String question_text = String
It edits the question in the database and it returns the id of the question in the form of:
{ id: int }
/api/question/
DELETE
q_id = Integer
{ success: "Question has been deleted" }
Returns a json object for a list of answers. By default this list is sorted in descending order by date created and it limits to 10 answers at most.
/api/answer/
GET
q_id = Integer, This is the id of the question you want the answers to
order = {asc, desc}
limit = Integer
{
answer_list: [{
id: int,
answer_text: string,
date_created: string,
user_id: {
username: string
},
point: Integer
}, ...]
}
/api/answer/?q_id=5&order=asc&limit=100
/api/answer/
POST
answer = String q_id = Integer, This is the id of the question you want to save the answer to
It saves the answer in the database and it returns the id of the newly created answer in the form of:
{ id: int }
/api/answer/
PUT
answer_text = String a_id = Integer, This is the id of the answer you want to edit
It edits the answer in the database and it the id of the answer in the form of:
{ id: int }
/api/answer/
DELETE
a_id = Integer, This is the id of the answer you want to delete
It edits the answer in the database and it the id of the answer in the form of:
{ success: "Answer has been deleted" }
/api/answer/vote/
POST
vote_type = "UP" or "DOWN"
a_id = Integer, This is the id of the answer you want to vote for
{
'sucess': 'Upvoted the answer',
'points': 1
}
/api/question/vote/
POST
vote_type = "UP" or "DOWN"
q_id = Integer, This is the id of the question you want to vote for
{
'sucess': 'Upvoted the question',
'points': 1
}
Registers a new user. If successful, the new user is associated with the sessionid and logged in. Returns a json representation of the registered user using the AccountSerializerPrivate serializer. If not successful, returns a error message.
/api/user/register/
POST
username = String, password = String
email = String
` {`
`"id": 6,`
`"password": "pbkdf2_sha25600000$etEbXsxl5tZB$/seTO4+B7dLMAIeHtnFxMBi1jjKLLMxXmcHILir8DTc=",`
`"last_login": "2018-02-18T00:05:34.662Z",`
`"is_superuser": false,`
`"username": "myuser2",`
`"first_name": "",`
`"last_name": "",`
`"email": "",`
`"is_staff": false,`
`"is_active": true,`
`"date_joined": "2018-02-18T00:05:34.361Z",`
`"groups": [],`
`"user_permissions": [],`
`"profile": {`
`"id": 6,`
`"user_id": 6,`
`"about_me": "Add something about yourself",`
`"reputation": 0,`
`"upvoted_questions": [],`
`"downvoted_questions": [],`
`"upvoted_answers": [],`
`"downvoted_answers": []`
`}`
`}`
If successful returns a json representation of the registered user using the AccountSerializerPrivate serializer. If not successful, returns a error message.
/api/user/me/
GET
` {`
`"id": 6,`
`"password": "pbkdf2_sha25600000$etEbXsxl5tZB$/seTO4+B7dLMAIeHtnFxMBi1jjKLLMxXmcHILir8DTc=",`
`"last_login": "2018-02-18T00:05:34.662Z",`
`"is_superuser": false,`
`"username": "myuser2",`
`"first_name": "",`
`"last_name": "",`
`"email": "",`
`"is_staff": false,`
`"is_active": true,`
`"date_joined": "2018-02-18T00:05:34.361Z",`
`"groups": [],`
`"user_permissions": [],`
`"profile": {`
`"id": 6,`
`"user_id": 6,`
`"about_me": "Add something about yourself",`
`"reputation": 0,`
`"upvoted_questions": [],`
`"downvoted_questions": [],`
`"upvoted_answers": [],`
`"downvoted_answers": []`
`}`
`}`
If successful returns a json representation of the registered user using the AccountSerializerPrivate serializer. If not successful, returns a error message.
/api/user/me/
POST
email = String
last_name = String
first_name = String
about_me = String
POST localhost:8000/api/user/me/
{"about_me":"My User's profile", "last_name":"MyName", "first_name":"MyFam", "email": null}
If successful returns a json representation of an user using the AccountSerializerPublic serializer. If not successful, returns a error message.
/api/user/name/{username}/
GET
`{
"id": 6,
"last_login": "2018-02-18T00:05:34.662Z",
"username": "myuser2",
"first_name": "",
"last_name": "",
"email": "",
"date_joined": "2018-02-18T00:05:34.361Z",
"profile": {
"about_me": "Add something about yourself",
"reputation": 0,
}
}`
Given a query string searches for questions that either contain the query in question_text or in username. The format is similar to Getting a list of questions. If successful, returns a json representation of the questions using the QuestionSerializer. By default this list is sorted in descending order by date created and it limits to 10 questions at most. If not successful, returns a error message.
/api/search/
GET
q = String (default ' ' )
order = {asc, desc}
limit = Integer (default 10)
`{ question_list: [{ id: int,
question_text: string,
date_created: string,
user_id: {
username: string
},
points: Integer
}, ...]
}`
/api/search/?q=how+to&limit=10&order=desc
Returns a json object of 4 lists: asked questions, answered questions, upvoted questions and downvoted questions.
/api/user/name/<:username>/questions/
GET
username = String
{ asked_questions: [{ id: int,
question_text: String,
question_head: String
date_created: String,
user_id: {
username: String
},
points: Integer
}, ...],
answered_questions: [{ id: int,
question_text: String,
question_head: String
date_created: String,
user_id: {
username: String
},
points: Integer
}, ...],
upvoted_questions: [{ id: int,
question_text: String,
question_head: String
date_created: String,
user_id: {
username: String
},
points: Integer
}, ...],
downvoted_questions: [{ id: int,
question_text: String,
question_head: String
date_created: String,
user_id: {
username: String
},
points: Integer
}, ...]
}
/api/user/name/testuser/questions/
Returns a json object with a list of jobs posted by a user
/api/user/name/<:username>/jobs/
GET
username = String
{posted_positions: [
{
job_id: Integer,
position: String,
job_type: String,
category: String,
company: String,
location: String,
description: String,
date_posted: String
}, ....
]
}
/api/user/name/testuser/jobs/
This url endpoint is used to allow users to apply for a job.
/api/job/application/
POST
job_id = Integer
{ success: "Application was successfully created."}
Winter 2018, SOEN341
Concordia University, Engineering and Computer Science Department