Restaurant Delete Controller

Building on our previous work with the RestaurantService, we'll now create the REST API endpoint that allows users to delete restaurants from our platform.

Implementing the Delete Endpoint

The delete endpoint follows REST principles by using the HTTP DELETE method to remove resources from our system.

Here's how we'll implement the delete endpoint in our RestaurantController:

@DeleteMapping("/{restaurantId}") public ResponseEntity<Void> deleteRestaurant(@PathVariable String restaurantId) { restaurantService.deleteRestaurant(restaurantId); return ResponseEntity.noContent().build(); }

Let's break down the key components of this implementation:

  • The @DeleteMapping annotation marks this method as handling HTTP DELETE requests
  • The /{restaurantId} path variable captures the ID of the restaurant to delete
  • The @PathVariable annotation binds the path variable to our method parameter
  • We return ResponseEntity.noContent() (HTTP 204) to indicate successful deletion

Response Status Code Choice

When implementing delete operations, choosing the right HTTP status code is important for REST API design.

We use HTTP 204 (No Content) because:

  • The operation was successful
  • There is no content to return to the caller
  • It clearly communicates that the resource no longer exists

Summary

  • Implemented the delete restaurants endpoint
  • Delete operations return HTTP 204 on success
© 2026 Devtiro Ltd. All rights reserved