Skip to content

API Endpoint Documentation

Halil Umut Özdemir edited this page May 24, 2020 · 34 revisions

1. REGISTRATION ENDPONT DOCUMENTATION - PYDOC

* BELOW YOU CAN FIND AS TEXT FORMAT, BUT FROM HERE A HTML FORMAT

* DONT FORGET YOU NEED TO DONWLOAD TO VIEW HTML


Help on module rest_api.register.register in rest_api.register:

NAME rest_api.register.register - Created on MAY 16, 2020

DESCRIPTION

This script controls the registration api of PLATON_API, using django&mysql backend.
    http://localhost:8000/api/register/
    
    'GET':
        Returns a random poem using an external API as JSON
    'POST':
        Gets dictionary from body.
        JSON Format : { 'name': "",                 string, Name parameter given by user
                        'surname': "",              string, Surname parameter given by user
                        'password1': "",            string, Password1 given by user
                        'password2':"",             string, Password2 given by user to check whether Password1 is matched.
                        'e_mail':"",                string, Email parameter given by user
                        'about_me':"",              string, About me parameter given by user
                        'job_name':"",              string, one word job description
                        'forget_password_ans':"",   string, forget password answer parameter given by user
                        'field_of_study':"" }       string, field of study parameter given by user

@author: Burak Omur, darktheorys
@company: Group7

FUNCTIONS

getPoem()
     returns a python dictionary, json that includes random poem

   This function returns a random poet using an external api.

getJobName(name)
     where name is the job name taken from user while registration
     returns uuid of normalized job, or empty string
    
   This function takes a string and using an external api it normalizes and returns the uuid of that job.

isValid(name, surname, password1, password2, email, about_me, job_uuid, forget_pw_ans, field_of_study)
        where 'name': string, Name parameter given by user
        where 'surname': string, Surname parameter given by user
        where 'password1': string, Password1 given by user
        where 'password2': string, Password2 given by user to check whether Password1 is matched.
        where 'email': string, Email parameter given by user
        where 'about_me': string, About me parameter given by user
        where 'job_uuid': string, job uuid parameter taken from external api
        where 'forget_pw_ans': string, forget password answer parameter given by user
        where 'field_of_study': string, field of study parameter given by user
        
        returns True if given values appropriate to insert in database, else False
    
    This function takes input parameters and checks them if they are valid and return the boolean result.

register_api(request)
     where 'request': HttpResponse, Name parameter given by user
    
     returns Json object if 'GET' requested else nothing
    
   This function takes Httpresponse object and if 'POST' request used, it inserts into database

register_page(request)
     where request HttpRequest to carry post and get requests

   This function takes a request and if POST, then it registers into system using another endpoint of this api
   If get, it renders a form to register and also a random poem.

2.Search Endpoint Documentation

This module makes a search in the registered users of the platform. You can give a search string and filters about the job and field of study of the user that you want to find. Also, a sorting criteria can be given as parameter. It searches and finds a list of users according to your criteria.

Input Format

This endpoint has no POST request. So if you send a post request it will give an error. The output is the following:

{
    "detail": "Method \"POST\" not allowed."
}

GET request parameters:

{   
    token = "Your token will be here!!",
    search_string = "The string that you want to search will be here",
    filter = {"job" = "job_filter", "field_of_study" = "field_of_study_filter" },
    sorting_criteria = "Sorting criteria will be here"
}
  • token parameter is explained in the Authentication part.
  • search_string parameter can be any string that you want to search. To see all of the users give an empty string(like search_string="" not search_string=) as the value of this parameter. You have to give the search_string parameter.
  • filter parameter is set of filters in the system. job can be any job in our system. field_of_study can be any string. filter parameter and its subparameters are not obligatory parameters. If you don' give this as a parameter system makes a search without filtering.
  • sorting_criteriais the sorting criteria of the result list. If any parameter is given the default sorting is made according to the semantic points of the results. name_increasing, name_decreasing, surname_increasing, surname_decreasing can be given as a parameter. It sorts the result list according to the parameter given.

Authentication

This module uses the tokens of the system for authentication. To use this endpoint, firstly register to the system with ../api/register/ endpoint and get a token using ../api/login/ endpoint. And give this token as an input to the request as:

{ 
    token = "Your token will be here!!" 
}

Sample Output

Request

GET http://127.0.0.1:8000/api/search/?token=824514797890967718&search_string=trial&filter={"job":"student"}

Output

[
    {
        "name": "Test1",
        "surname": "Test1",
        "e-mail": "[email protected]",
        "about_me": "I am a test user and I will be deleted when API is deployed!!",
        "job": "Student",
        "field_of_study": "Test Field1"
    },
    {
        "name": "Test1",
        "surname": "Test1",
        "e-mail": "[email protected]",
        "about_me": "I am a test user and I will be deleted when API is deployed!!",
        "job": "Student",
        "field_of_study": "Test Field1"
    },
    {
        "name": "Test1",
        "surname": "Test1",
        "e-mail": "[email protected]",
        "about_me": "I am a test user and I will be deleted when API is deployed!!",
        "job": "Student",
        "field_of_study": "Test Field1"
    },
    {
        "name": "Test1",
        "surname": "Test1",
        "e-mail": "[email protected]",
        "about_me": "I am a test user and I will be deleted when API is deployed!!",
        "job": "Student",
        "field_of_study": "Test Field1"
    }
]

Error Codes

  • Token Error:

GET http://127.0.0.1:8000/api/search/?search_string=trial&filter={"job":"student"}

"You have to give your token"
  • 3rd Party API Error:

GET http://127.0.0.1:8000/api/search/?token=824514797890967718&search_string=trial

"There is a problem about the 3rd party APIs that I used. Please try again!!"
  • Input Error:

GET http://127.0.0.1:8000/api/search/?token=824514797890967718&search_string=trial&filter={"job":"dent"}

"Wrong input. Please give an appropriate input!!"








Clone this wiki locally