Collections Blog Python Model code and SQLite Database.

  • From VSCode using SQLite3 Editor, show your unique collection/table in database, display rows and columns in the table of the SQLite database.

Screenshot 2024-04-21 at 6 29 50 PM

  • Opening text file that contains all text data and line by line reads it and organizes the values in to a database

    • The code sets up a structure to organize and store text data into a database.

Screenshot 2024-04-21 at 6 23 50 PM

  • Show your unique code that was created to initialize table and create test data from VSCode model.
    • The function reads a text file line by line, interprets each line as a dictionary, and then stores each dictionary’s values into a database as a new entry.

Lists and Dictionaries

Screenshot 2024-05-08 at 10 37 54 AM

  • “args” is a dictionary containing the parsed request arguments.

Screenshot 2024-05-08 at 10 40 08 AM

  • This line returns a dictionary generated by the to_dict() method

Screenshot 2024-05-08 at 10 44 27 AM

  • This line constructs a list of dictionaries, with each dictionary representing the Data object attributes.

  • Show a list as extracted from database as Python objects in VSCode using Debugger.

Screenshot 2024-05-08 at 10 47 44 AM

  • In the get method of the DataListAPI class,I am querying the database to fetch all Data objects using db.session.query(Data).all(). This returns a list of data objects. Then, i’m using a list comprehension to iterate over this list (for d in data) and convert each data object into a dictionary using the to_dict() method (d.to_dict()). Finally,the code is returning this list of dictionaries as the response.

APIs and JSON

  • In VSCode, show Python API code definition for request and response using GET, POST, UPDATE methods. Discuss algorithmic condition used to direct request to appropriate Python method based on request method.

Screenshot 2024-04-24 at 10 28 08 PM

  • A resource is included in the API at the suitable URL.
  • When a request is dispatched to this URL, the corresponding function is invoked based on the type of request sent.

Python API code definition for request and response using GET, POST, UPDATE methods in VSCode

Screenshot 2024-04-21 at 6 59 45 PM

  • Show algorithmic conditions used to validate data on a POST condition in VSCode.

Screenshot 2024-04-23 at 11 08 05 PM

Screenshot 2024-04-21 at 6 50 34 PM

-The code processes incoming data for storage in a database and checks to make sure no required information is missing. If data is correct, it saves it; if not, it sends an error message.

Screenshot 2024-04-21 at 7 01 19 PM

  • The code snippet is designed to update a database entry. It first checks that all necessary information is provided, and if anything is missing, it reports an error; otherwise, it proceeds to update the entry with the new data.

Show URL request and Body requirements for GET, POST, and UPDATE methods in Postman.

Show the JSON response data for 200 success conditions on GET, POST, and UPDATE methods in Postman.

Screenshot 2024-04-23 at 10 39 18 PM

Screenshot 2024-04-23 at 11 00 12 PM

Screenshot 2024-04-23 at 11 05 20 PM

Show the JSON response for error for 400 when missing body on a POST request in Postman.

Screenshot 2024-04-24 at 10 42 03 PM

Screenshot 2024-04-23 at 11 17 46 PM

Show the JSON response for error for 404 when providing an unknown user ID to a UPDATE request in Postman.

Screenshot 2024-04-24 at 10 56 56 PM

Frontend

  • Blog JavaScript API fetch code and formatting code to display JSON.

Screenshot 2024-04-21 at 8 47 40 PM

  • The code preforms a API fetch request to retrieve college data from a local server. After making the request, it processes the JSON response, and uses the data to update and display college search results on the web page, and logs the information to the console. If there’s an error during the fetch, it catches and logs the error.

Show response of JSON objects from fetch of GET, POST, and UPDATE methods in Chrome inspect.

Screenshot 2024-04-21 at 8 45 13 PM

  • Get request
    • This fetch request gets data from the database based ont he colleges id. In this example, every college is fetched. The method returns the JSON object as a python dictionary.

Screenshot 2024-04-21 at 8 57 13 PM

  • Post request

Screenshot 2024-04-21 at 9 19 03 PM

  • Update Request

Show a demo (GET) of obtaining an Array of JSON objects that are formatted into the browsers screen in the Chrome browser.

Screenshot 2024-04-24 at 11 22 15 AM

  • The console on the right shows an array of university names, indicating these the data fetched from the server to populate the “Safety Schools” list