7 days of WordPress plugins, themes & templates - for free!* Unlimited asset downloads! Start 7-Day Free Trial

Next lesson playing in 5 seconds

Cancel
  • Overview
  • Transcript

4.6 Adding the `DELETE` Handler to the API

Adding, retrieving, and updating objects in our app is great. But there is one crucial piece of the puzzle that we're missing. We need to be able to delete objects from our app. In this lesson, we'll do just that by creating a DELETE request handler.

1.Introduction
2 lessons, 07:21

1.1
Introduction
01:02

1.2
Prerequisites
06:19

2.Getting Started
3 lessons, 30:48

2.1
Creating the App Structure
11:46

2.2
Creating the Server-Side Entry Point
10:14

2.3
Starting the Angular and Express Apps
08:48

3.Setting Up the Mongo Database
4 lessons, 27:53

3.1
Getting MongoDB Up and Running
06:08

3.2
Connecting to MongoDB
06:47

3.3
Creating the Database Schema
07:49

3.4
Creating a Simple Data Access Layer
07:09

4.Creating an API With Express
6 lessons, 29:16

4.1
Handling Requests in Express
09:57

4.2
Taking Advantage of the Express Router
05:52

4.3
Adding the `GET` Handler to the API
05:34

4.4
Adding the `POST` Handler to the API
03:18

4.5
Adding the `PUT` Handler to the API
02:17

4.6
Adding the `DELETE` Handler to the API
02:18

5.Building the Front-End Angular App
6 lessons, 45:52

5.1
Creating the Front-End Models
06:57

5.2
Creating an Angular Service
07:31

5.3
Making HTTP Requests From the Service
08:33

5.4
Setting Up the User Interface
09:05

5.5
Creating All the Components
05:28

5.6
Adding Routing to the App
08:18

6.Creating the App Components
12 lessons, 1:00:02

6.1
Adding the View Lawn Markup
05:55

6.2
Adding the View Lawn Code
06:51

6.3
Adding the Add Lawn Markup
04:34

6.4
Adding the Add Lawn Code
07:41

6.5
Adding the Edit Lawn Markup
03:06

6.6
Adding the Edit Lawn Code
04:11

6.7
Adding the View Application Markup
02:54

6.8
Adding the View Application Code
07:46

6.9
Adding the Add Application Markup
02:16

6.10
Adding the Add Application Code
04:49

6.11
Adding the Edit Application Markup
04:20

6.12
Adding the Edit Application Code
05:39

7.Conclusion
1 lesson, 03:18

7.1
Conclusion
03:18


4.6 Adding the `DELETE` Handler to the API

And now for my final trick, we're gonna add in the functionality for the delete. And we're gonna be doing this very similarly to what we've done so far. So we're gonna start with our router and this time we're gonna handle the delete function. And now remember, we're gonna be doing the deletes by the ID. Again, we could have done this a couple of different ways. And just as a refresher, what we wound up doing in here is for the delete, all we are passing in is the ID and then the callback. And actually, there's really not a whole lot to do in the callback. Maybe just process the error because that's all we're really gonna be dealing with. There's really nothing else that we're gonna expect to be passing back. Cuz once we're deleting an object, we're not really expecting much else to be there for that particular object. But you can obviously change a simple notation to follow whatever sort of patterns you would like to. So we're gonna have the response or the request, the response and the next. And then we are also going to be using our Lawn.deleteLawn function. And we need to be passing in the ID, so once again that's gonna be coming from the url, so we'll say, request.params.id. And then we can pass in our callback. And then in here we'll say once again, if error then we'll go ahead and return the next error. And then you could just leave it at that. There's really not a whole lot or any really main reason to do the second part of it cuz we wouldn't be expecting to be getting much back from this. Or you can add it in there just to be complete or at least to follow the same pattern that we've done before. But it's really not overly necessary. So there we have our delete, we're passing in the ID. We will use our deleteLawn function. We're gonna pass in the parameter id coming from the URL. And then if everything goes well, then we should no longer have that lawn in the database, and then we can do whatever we want from the front end perspective. We can remove it from the UI, so on and so forth. But I'm gonna leave that all for the next section when we start to build out the UI. Now that we have some basics at least from a route perspective, we have all of our git functionality, our post functionality put and delete. And we'll be ready to take the next step.

Back to the top