1 00:00:00,630 --> 00:00:04,510 The delete route is going to be a lot like the update quote route, 2 00:00:04,510 --> 00:00:08,220 only it will completely remove the specified quote from the data store. 3 00:00:08,220 --> 00:00:09,785 To create a delete route, 4 00:00:09,785 --> 00:00:14,421 we'll want to handle delete requests sent to the slash quote slash ID route. 5 00:00:18,360 --> 00:00:21,986 Again, we'll need the callback to be an asynchronous function that takes in 6 00:00:21,986 --> 00:00:23,676 the request and response objects. 7 00:00:28,518 --> 00:00:31,251 And to use the async await syntax, 8 00:00:31,251 --> 00:00:36,153 we'll need a try-catch block.bbb Inside the catch block, 9 00:00:36,153 --> 00:00:42,011 we'll copy and paste the same error handling code from previous videos. 10 00:00:46,086 --> 00:00:50,693 Inside the try block, we'll again get the specified quote by grabbing the ID from 11 00:00:50,693 --> 00:00:54,382 the request parameters and passing it to the get quote function. 12 00:01:03,720 --> 00:01:05,798 Once we’ve got the quote we’re looking for, 13 00:01:05,798 --> 00:01:08,470 we can use the delete quote method from our records module. 14 00:01:13,815 --> 00:01:17,366 We'll wanna wait for the delete quote method to finish before we send back 15 00:01:17,366 --> 00:01:19,666 the proper status message and end the request. 16 00:01:26,678 --> 00:01:29,655 We'll send back the same no content status message. 17 00:01:30,870 --> 00:01:34,360 Let's save this and take a peek inside of our data store. 18 00:01:34,360 --> 00:01:38,740 From testing and such, I have several duplicate quotes to delete. 19 00:01:38,740 --> 00:01:43,592 Go to postman and send a delete request to the ID of the quote you want to delete. 20 00:01:45,137 --> 00:01:48,229 So I want to delete quote 1492. 21 00:01:51,690 --> 00:01:53,121 Send. 22 00:01:53,121 --> 00:01:54,521 And close this for now. 23 00:01:56,428 --> 00:01:59,240 Let's see if we can figure out what went wrong here. 24 00:01:59,240 --> 00:02:03,440 I can see I have a typo in my route. 25 00:02:03,440 --> 00:02:05,160 So let's try this again. 26 00:02:05,160 --> 00:02:08,500 And we've got a 204 No Content status code. 27 00:02:08,500 --> 00:02:13,330 Great, let's take a look inside data.json. 28 00:02:13,330 --> 00:02:15,380 And that quote is gone. 29 00:02:15,380 --> 00:02:19,483 For practice, I encourage you to look at the put route we did in a previous 30 00:02:19,483 --> 00:02:25,340 video,and implement some extra additional error handling for our delete route. 31 00:02:25,340 --> 00:02:29,270 What if the client requests to delete a quote that doesn't exist? 32 00:02:29,270 --> 00:02:30,027 Well done. 33 00:02:30,027 --> 00:02:34,246 We now have a fully functioning rest API with all of its cred operations. 34 00:02:34,246 --> 00:02:37,563 We can create, read, update, and delete quotes. 35 00:02:37,563 --> 00:02:41,583 You may have noticed that we have quite a bit of unwieldy and repeating code. 36 00:02:41,583 --> 00:02:45,088 In the next part of the course, we'll use express middleware to clean up 37 00:02:45,088 --> 00:02:48,248 some of our repeating code, see ways to structure our projects so 38 00:02:48,248 --> 00:02:52,760 that our code is more modular, and learn how we can handle errors globally. 39 00:02:52,760 --> 00:02:55,810 And of course, we'll write a route that returns a random quote. 40 00:02:55,810 --> 00:02:56,440 I'll see you there.