Skip to content

Users API

Kerry Gougeon Ducharme edited this page Feb 16, 2018 · 6 revisions

Users

Types Returned: user and users

First let me start by giving a basic explanation of the user and users data types. A user object might look something like:

{"id":100, "fname": 'Jon', "lname": 'Mongeau', "email":'[email protected]', "password_hash":'PASSWORD_HASH_HERE', "register_date": '2017-30-01', "engineer": 'software', "display_image": '1.jpg', "verified": 1 , "ups":0, "downs":0}

A users object would just be an array of user objects defined above:

[ {"id":100, "fname":'Jon', ...} , {"id":13, "fname":'Kerry', ...} , {"id":42, "fname":'Ramez', ...} , ... ]

For example in a programming language like JavaScript or Python if the variable usersArray contained a users object we might access the last name of the first user by doing:

// JS
usersArray[0].lname
# Python: 
usersArray[0]['lname']

In this case the value would be Mongeau. It is important to realize here that these 'objects' are actually JSON. In Python they take on the type dict (for dictionary) and are accessed using the square bracket notation. In JavaScript they take on the type object and are accessed using the dot notation.

User Routes

In order for the front-end to access information from the back-end it is important that a protocol be established so as to avoid ambiguity. We have decided to go with a REST api. The front-end chooses a route to send the message to, a method with which to send it to and data with which the back-end can interact with.

The basic structure for the return is bool success, string status, string message as well as any other entity send back, in this case user and user objects as well.

route: /api/users/

HTTP Requests Description of Action Expected Data from Front-End Response (JSON)
POST Creates a new user. fname, lname, email, password, engineer, display_image success, status, message
DELETE Deletes all users. None success, status, message
GET Get all users. None success, status, message, users

route: /api/users/12345

HTTP Requests Description of Action Expected Data from Front-End Response (JSON)
PUT Updates user. fname, lname, engineer, display_image success, status, message
DELETE Deletes user. None success, status, message
GET Get user information. None success, status, message, user

route: /api/users/authenticate/

HTTP Requests Description of Action Expected Data from Front-End Response (JSON)
POST Authenticate user. email, password success, status, message, user

route: /api/users/email/

HTTP Requests Description of Action Expected Data from Front-End Response (JSON)
POST Checks if email exists. email success, status, message