Skip to content

REST API Documentation

Chirac Manoukian edited this page Mar 28, 2018 · 31 revisions

REST API Documentation

You will find all information about the REST API calls in this section.

Getting a single question

Returns a json object of a single question.

URL:

/api/question/:id/

Method:

GET

URL parameters:

Required Parameters:

id = Integer

Success Response:

{ id: Integer,question_head: String, question_text: String, date_created: String, user_id: { username: String } }


Getting a list of questions

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.

URL:

/api/question/

Method:

GET

URL Parameters:

Optional parameters:

order = {asc, desc}

limit = Integer

Success Response:

{
    question_list: [{
        id: int,
        question_text: String,
        question_head: String
        date_created: String,
        user_id: {
            username: String
        },
        points: Integer
    }, ...]
}

Sample Request:

/api/question/?limit=10&order=desc


Saving a question in the database

URL:

/api/question/

Method:

POST

Data Parameters:

Required Parameters:

question_head = String

Optional Parameters:

question_text = String

Success Response:

It saves the question in the database and it returns the id of the newly created question in the form of:

{ id: int }

Editing a question in the database

URL:

/api/question/

Method:

PUT

Data Parameters:

Required Parameters:

q_id = Integer question_head = String question_text = String

Success Response:

It edits the question in the database and it returns the id of the question in the form of:

{ id: int }

Deleting a question in the database

URL:

/api/question/

Method:

DELETE

Data Parameters:

Required Parameters:

q_id = Integer

Success Response:

{ success: "Question has been deleted" }

Getting a list of answers for a question

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.

URL:

/api/answer/

Method:

GET

URL Parameters:

Required parameters:

q_id = Integer, This is the id of the question you want the answers to

Optional parameters:

order = {asc, desc}

limit = Integer

Success Response:

{
    answer_list: [{
        id: int,
        answer_text: string,
        date_created: string,
        user_id: {
            username: string
        },
        point: Integer
    }, ...]
}

Sample Request:

/api/answer/?q_id=5&order=asc&limit=100


Saving an answer in the database

URL:

/api/answer/

Method:

POST

Data Parameters:

Required Parameters:

answer = String q_id = Integer, This is the id of the question you want to save the answer to

Success Response:

It saves the answer in the database and it returns the id of the newly created answer in the form of:

{ id: int }

Editing an answer in the database

URL:

/api/answer/

Method:

PUT

Data Parameters:

Required Parameters:

answer_text = String a_id = Integer, This is the id of the answer you want to edit

Success Response:

It edits the answer in the database and it the id of the answer in the form of:

{ id: int }

Deleting an answer in the database

URL:

/api/answer/

Method:

DELETE

Data Parameters:

Required Parameters:

a_id = Integer, This is the id of the answer you want to delete

Success Response:

It edits the answer in the database and it the id of the answer in the form of:

{ success: "Answer has been deleted" }

Voting for an answer

URL:

/api/answer/vote/

Method:

POST

Data Parameters:

Required Parameters:

vote_type = "UP" or "DOWN"

a_id = Integer, This is the id of the answer you want to vote for

Success Response:

{
    'sucess': 'Upvoted the answer',
    'points': 1
}

Voting for a question

URL:

/api/question/vote/

Method:

POST

Data Parameters:

Required Parameters:

vote_type = "UP" or "DOWN"

q_id = Integer, This is the id of the question you want to vote for

Success Response:

{
    'sucess': 'Upvoted the question',
    'points': 1
}

Registering a user

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.

URL:

/api/user/register/

Method:

POST

Data Parameters:

Required parameters:

username = String, password = String

Optional parameters:

email = String

Sample Response (AccountSerializerPritave)

` {`
     `"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": []`
     `}`
`}`

Getting information about the registered user

If successful returns a json representation of the registered user using the AccountSerializerPrivate serializer. If not successful, returns a error message.

URL:

/api/user/me/

Method:

GET

Sample Response (AccountSerializerPritave)

` {`
     `"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": []`
     `}`
`}`

Modifying information of the registered user

If successful returns a json representation of the registered user using the AccountSerializerPrivate serializer. If not successful, returns a error message.

URL:

/api/user/me/

Method:

POST

Optional parameters:

email = String

last_name = String

first_name = String

about_me = String

Sample Request:

POST localhost:8000/api/user/me/ {"about_me":"My User's profile", "last_name":"MyName", "first_name":"MyFam", "email": null}


Getting information about a user by username

If successful returns a json representation of an user using the AccountSerializerPublic serializer. If not successful, returns a error message.

URL:

/api/user/name/{username}/

Method:

GET

Success Response (AccountSerializerPublic):

 `{
     "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,
     }
 }`

Searching for a question

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.

URL:

/api/search/

Method:

GET

URL Parameters:

Optional parameters:

q = String (default ' ' )

order = {asc, desc}

limit = Integer (default 10)

Success Response (QuestionSerializer):

`{ question_list: [{ id: int,
                    question_text: string,
                    date_created: string,
                    user_id: {
                        username: string
                    },
                    points: Integer
                   }, ...]
}`

Sample Request:

/api/search/?q=how+to&limit=10&order=desc


Getting a list of questions asked and answered by user

Returns a json object of 4 lists: asked questions, answered questions, upvoted questions and downvoted questions.

URL:

/api/user/name/<:username>/questions/

Method:

GET

URL Parameters:

username = String

Success Response:

{ 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
                   }, ...]
}

Sample Request:

/api/user/name/testuser/questions/


Getting a list jobs posted by a user

Returns a json object with a list of jobs posted by a user

URL:

/api/user/name/<:username>/jobs/

Method:

GET

URL Parameters:

username = String

Success Response:

{posted_positions: [
        {
            job_id: Integer,
            position: String,
            job_type: String,
            category: String,
            company: String,
            location: String,
            description: String,
            date_posted: String
        }, ....
]
}

Sample Request:

/api/user/name/testuser/jobs/


Applying for a job

This url endpoint is used to allow users to apply for a job.

URL:

/api/job/application/

Method:

POST

Data Parameters:

Required parameters:

job_id = Integer

Sample Response

{ success: "Application was successfully created."}

Clone this wiki locally