Data Structure Project Writeup

Collections

A model in the context of a SQLite Database is a table: a collection of data related to each other. An example of a model and the one I integrated was the user table which takes in a userID, an id (for sql identification purposes) a profile picture as text as the image is sent in base64, and other attributes.

The code that initializes the table is as follows and on GitHub

This initializes the table in the SQL database and refers the database table name as "users". Every attribute referenced in the class is a column in the table. The unique keyword means that it can only have this value (although it is not a primary key). A primary key is the actual id of the row, and should be used for identification purposes and is an integer.

Lists and Dictionaries

Dictionaries and Lists are used in the user file as there is a dictionary with each key's values being a list after the values are queried from the database. Users is a table that is queried and the data queried is stored in a dictionary or hashmap, and the values of each key is an array.

API and JSON

The API is used to communicate between the frontend and the server. GET requests are used to retrieve data from the server and POST requests is more dynamic as it can be used for various purposes. In the context of the project it is used to set a value in the database, and retrieve data.

JSON or Javascript Object Notation is used to transmit a "name" for the value which is the key, and the value itself, so if I wanted to recieve a username, the key is "username" and the value would be the actual username value

Example of POST request

In the signup route, POST is used as it recieves values from the signup page, like the username password and etc, and then the server then sends a JWT (JSON Web Token) that acts as an authenticator for the user

Example of GET

Here the GET first runs token_required which just checks if the JWT sent from the client is valid, and if it is valid it will then get the values of the user. This returns a json with the keys all corresponding to the current_user being a row in the Users column.

That actual validation in token_required is as follows, it checks for an Authorization header in the request (JWT) and if there is one is one it will try to filter by the ID specified in the JWT.

Postman

Postman is a service that allows for the testing of APIs, by sending various requests to the a specific address. Here I am refering to the login route on the server backend, with the body of userID and password sent in JSON format.

200 Status: meaning success

400 Status: meaning failure, with it failing due to a lack of a body.

Frontend Work

The actual client is on the frontend and here is the GET/POST work on the frontend with this being the 200 status

The 401 unauthorized in the case the client does not have the correct credentials

These are the values receieved in the 200 request, being the JWT recieved from the server.

Finally here is the javascript that handles the GET and POST requests, The script is fetching the specific address, with eitehr POST or GET depending on what it's needed for, if the response is "ok" or a 200 response, it will parse the JSON.