Let's do a delete operation. First, you can see that I have the customer whose ID is 45. So I click the Run button, I see the data. Let's go back, add a new function here, which is supposed to return the deleted customer data. So I'll say response entity of customer type. Let's call it as delete customer.
We want to take the ID from the font variable, so I can actually copy this part and then paste over here. And then of course, we have to search for this customer. If the customer is not fond, we may want to respond with 404. So let's do that. We had done that earlier here. So we can say that we want to get this customer.
So we're going to copy and paste the same thing. So we got the customer. But what if there is an error, so the customer doesn't exist? So I like to put that in a try catch block. So I'm going to put a try, catch And paste over here. So if there is an exception, I'm going to say here that there is a four not four.
So I cannot delete this because the customer doesn't exist. So I can say that customer doesn't exist, but if the customer exists, I want to delete that first by doing a report dot delete, and then I supply either delete by ID or delete the entity itself. So I can say C one and then I will say here, return response entity dot Okay, and then supply c one, because C one happens to be the data that we deleted. So as far as the mapping is concerned, it is like put mapping, but there is no request body but we just have to say at the rate, delete mapping, and then we say slash ID because we have to say whose record we want to delete. So as soon as I save this Spring Boot restarting the application. Let's go back to the browser and check once again.
So I'm going to say select star from customers where ID is 45. So we get the data. Let's go back to postman. Now make the Delete request this time. and delete request doesn't care about the body, there is no need of body so I can remove that. So there's a delete 7777 apa customers 45.
So I click on Send, of course, it's going to delete, and I would get the data back. But if I tried to send it again, you can see it's going to be a four, not four, because there is no data. So I click on Send. And obviously it says four, not four. Because this record is not there in the database anymore. Let's verify that by going to the database and click on the run button here.
And you see that no rows found for id 45.