Question: In this assignment you will need to set up one GET and one POST method. When GET is called, return all objects from the global
In this assignment you will need to set up one GET and one POST method. When GET is called, return all objects from the global list. When POST is called, the user will pass a request object using swagger identical to the object in the list with different values. If Product id exists in the list, then modify the values of the product in the list otherwise just add that object to the list. Also, you must define a request object on the top of the class above app initialization
without using Flask lest use pydantic
After you created the appFastAPI variable for our API you need to declare our global list of products. We are using a list for now as our database.
In future assignments we will be integrating a database and not be using the list.
Products Name: 'Apple', 'Price': 'Type': 'Fruit'
Name: 'Orange', 'Price': 'Type': 'Fruit'
Name: 'Tomato', 'Price': 'Type': 'Fruit'
Name: 'Cabbage', 'Price': 'Type': 'Vegetable'
Name: 'Potato', 'Price': 'Type': 'Vegetable'
Name: 'Potato', 'Price': 'Type': 'Vegetable'
Request Object
The request object will be used in the POST methods to modify or add new data. The object must contain all variables of the "Products" object from the dictionary list.
Endpoints
products
Write a function that is mapped to the following endpoint: products
Type: GET
Method Name: getproducts
Parameters: NONE
Return: Products
The above method should return a list of all products.
productsmod
Write a function that is mapped to the following endpoint: productsmod
Type: POST
Method Name: updateproduct
Parameters: product : Product the Request Object
Return: string
The above method should return "Added New Product" if the request object didn't exist in the global list or it should return "Modified Product" if the product already exists. For this you need to check if the item is already in the list. Remember that typically one field is a unique identifier or ID for an object in a listdatabase
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
