For the DELETE method, items are deleted by index, i.e., the query string will hold the...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
For the DELETE method, items are deleted by index, i.e., the query string will hold the index of the item to be deleted within the list. Note that the index starts from 0. 1. Create a new handler for the DELETE method. Call the handler "DELETEhandler". Like the POST handler, pass the file name, the query string object, and the callback function. 2. Retrieve the list from the file using the helper function. 3. Check that the index passed in the query string exists in the list. i.e., the index to be deleted must be less than the length of the list a. If the index is equal or greater than the length of the list, then return the status code '404' and message 'NOT FOUND'. b. 4. In the server handler, call the DELETE handler and pass to it the json file, the query string, and the callback function that will return the status code and message. 5. Fill the response header with the status code, and content type (check the code from the POST handler above). 6. Send the response with the message returned from the handler (check the code from the POST handler above). 7. Update the code for the invalid path to return an appropriate status code and message as before 8. Save your code and run the server 9. Using Postman, check the correct operation of the server for both paths a. Send a request to delete an item at an index that is not in the list. b. Send a request to delete an item in the list and use the GET method to display the list after deletion. Otherwise, remove the item at the given index from the list and store the list back in the file. For the PUT method, items to be updated are identified by their index, i.e., the query string will hold the index of the item in addition to the field(s) to be updated. Note that the index starts from 0 and all fields for the todo list and shopping list can be updated. 1. Create a new handler for the PUT method. Call the handler "PUTHandler". Like the POST handler, pass to the handler the file name, the query string object, and the callback function. 2. In the handler, retrieve the list from the json file using the helper function. 3. Check that the index passed in the query string exists in the list. i.e., the index to be updated must be less than the length of the list a. If the index is equal or greater than the length of the list, then return the status code '404' and message 'NOT FOUND'. b. Otherwise, get the name of the keys in the query string object and update the relevant fields in the retrieved item (Hint: check Object.keys() static method and indexOf() method of Array instances in JS). Note that you will use a direct assignment statement to update the field. 4. In the routing logic for the PUT method, call the PUT handler passing to it the corresponding json file, the query string, and the callback function. The call back function has two parameters that will return the status code and corresponding message from the PUT handler. 5. Fill the response header with the status code, and content type (check the code from the POST handler above). 6. Send the response with the message returned from the handler (check the code from the POST handler above). 7. Update the code for the invalid path to return an appropriate status code and message as before. For the DELETE method, items are deleted by index, i.e., the query string will hold the index of the item to be deleted within the list. Note that the index starts from 0. 1. Create a new handler for the DELETE method. Call the handler "DELETEhandler". Like the POST handler, pass the file name, the query string object, and the callback function. 2. Retrieve the list from the file using the helper function. 3. Check that the index passed in the query string exists in the list. i.e., the index to be deleted must be less than the length of the list a. If the index is equal or greater than the length of the list, then return the status code '404' and message 'NOT FOUND'. b. 4. In the server handler, call the DELETE handler and pass to it the json file, the query string, and the callback function that will return the status code and message. 5. Fill the response header with the status code, and content type (check the code from the POST handler above). 6. Send the response with the message returned from the handler (check the code from the POST handler above). 7. Update the code for the invalid path to return an appropriate status code and message as before 8. Save your code and run the server 9. Using Postman, check the correct operation of the server for both paths a. Send a request to delete an item at an index that is not in the list. b. Send a request to delete an item in the list and use the GET method to display the list after deletion. Otherwise, remove the item at the given index from the list and store the list back in the file. For the PUT method, items to be updated are identified by their index, i.e., the query string will hold the index of the item in addition to the field(s) to be updated. Note that the index starts from 0 and all fields for the todo list and shopping list can be updated. 1. Create a new handler for the PUT method. Call the handler "PUTHandler". Like the POST handler, pass to the handler the file name, the query string object, and the callback function. 2. In the handler, retrieve the list from the json file using the helper function. 3. Check that the index passed in the query string exists in the list. i.e., the index to be updated must be less than the length of the list a. If the index is equal or greater than the length of the list, then return the status code '404' and message 'NOT FOUND'. b. Otherwise, get the name of the keys in the query string object and update the relevant fields in the retrieved item (Hint: check Object.keys() static method and indexOf() method of Array instances in JS). Note that you will use a direct assignment statement to update the field. 4. In the routing logic for the PUT method, call the PUT handler passing to it the corresponding json file, the query string, and the callback function. The call back function has two parameters that will return the status code and corresponding message from the PUT handler. 5. Fill the response header with the status code, and content type (check the code from the POST handler above). 6. Send the response with the message returned from the handler (check the code from the POST handler above). 7. Update the code for the invalid path to return an appropriate status code and message as before.
Expert Answer:
Answer rating: 100% (QA)
Heres an example implementation of the DELETE and PUT handlers based on the instructions provided javascript const fs requirefs const url requireurl H... View the full answer
Related Book For
Concepts of Database Management
ISBN: 978-1285427102
8th edition
Authors: Philip J. Pratt, Mary Z. Last
Posted Date:
Students also viewed these programming questions
-
5. Apply two iterations of the successive shortest path algorithm to the minimum cost flow problem shown below. (Copy) (0,0) (1,00) (0, 1) (3,00) (0, 2) (1,00) (0,3) (0,2) b(1)=8( 32.00) b(8)=-8...
-
15. Given the code int x, n: scanf("%d",&n); for(x=-1: x
-
This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of an array of objects as a class data...
-
At Acme Corp., the firm's senior managers approach marketing implementation with the belief that marketing strategy should be developed at the top of the organization and then transmitted to lower...
-
In Fig. 8-20, we see how Alice can send Bob a signed message. If Trudy replaces P, Bob can detect it. But what happens if Trudy replaces both P and the signature?
-
An aqueous solution containing MgCl2 and HCl was analyzed by first titrating a 25.00-mL aliquot to a bromocresol green end point with 17.53 mL of 0.02932 M NaOH. A 10.00-mL aliquot was then diluted...
-
In a survey of 8-to 18-year-old heavy media users in the United States, 47% said they get fair or poor grades (C and below). You randomly select forty-five 8- to 18-year-old heavy media users in the...
-
SML and WACC an all equity firm is considering the following projects: The T-bill rate is 5 percent, and the expected return on the market is 12 percent. a. Which projects have a higher expected...
-
Havana Hats makes the world's best hats. Information for the last eight months follows: Number of Hats Month January Produced 7,800 February 7,250 March 6,150 April 5,250 May 4,500 June 2,100 July...
-
1. Do you believe brand personality plays a major part in decision making? Explain. 2. After evaluating Table A, which alcohol brand will Greg be most likely to purchase? 3. Using Table B and taking...
-
A. Title of article B. Thesis/argument C. Their definition/idea of rhetoric D. Definitions of key terms E. Main takeaways F. One question you have about the reading The Rhetorical Situation Lloyd F....
-
Lo You've collected the following information from your favorite financial website. 52-Week Price Hi Dividend Stock (Dividend) Yield % PE Ratio Close Price Net Change 77.40 10.43 Acevedo .36 2.6 6...
-
A quantitative data set has mean 20 and standard deviation 3. Apply Chebyshev's rule to complete parts (a) and (b) below. a. At least 96% of the observations lie between which two values? At least...
-
Parkview Company issued $400,000 of 15-year, 7% callable bonds payable on July 31, 2025, at 97. On July 31, 2028, Parkview Company called the bonds at 104. Assume annual interest payments....
-
Sofa Gomez runs a mobile pet grooming service. She charges $30 direct labor per grooming hour. She applies overhead to jobs on the basis of grooming hours. She predicts 930 grooming hours for the...
-
In the process of saving some money for my kids college I plan to make six annual deposits of $4000 into a secret savings account that pays an interest of 4% compounded annually. Two years after...
-
Can a transformer be used to transform direct voltage and direct current? Justify your answer.
-
(a) Find the equation of the tangent line to f(x) = x 3 at the point where x = 2. (b) Graph the tangent line and the function on the same axes. If the tangent line is used to estimate values of the...
-
The owner of Colonial Adventure Tours knows the importance of the SQL language in database management. He realizes that he can use SQL to perform the same functions that you performed with queries in...
-
Write the SQL commands to grant the following privileges: a. User Stetson must be able to retrieve data from the Customer table. b. Users Webster and Bremer must be able to add new orders and order...
-
Describe the results of the division process in relational algebra.
-
Determine whether each of the following statements is true or false: Management accountants should be technically proficient, but they dont need strong oral and written communication skills.
-
Determine whether each of the following statements is true or false: Management accountants should be proficient in Excel.
-
Determine whether each of the following statements is true or false: The Association of International Certified Professional Accountants (AICPA) issues the Certified Management Accountant (CMA)...
Study smarter with the SolutionInn App