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.
-
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.
- 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
- “args” is a dictionary containing the parsed request arguments.
- This line returns a dictionary generated by the to_dict() method
-
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.
- 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.
- 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
- Show algorithmic conditions used to validate data on a POST condition in VSCode.
-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.
- 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.
Show the JSON response for error for 400 when missing body on a POST request in Postman.
Show the JSON response for error for 404 when providing an unknown user ID to a UPDATE request in Postman.
Frontend
- Blog JavaScript API fetch code and formatting code to display JSON.
- 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.
- 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.
- Post request
- Update Request
Show a demo (GET) of obtaining an Array of JSON objects that are formatted into the browsers screen in the Chrome browser.
- 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