> ## Content Index
> Fetch the complete content index at: https://www.saraburke.net/llms.txt
> Use this file to discover other available public pages before exploring further.

# Blocking Specific Request Methods in Spring Data REST
- URL: https://www.saraburke.net/blocking-specific-request-methods-in-spring-data-rest/
- Published: 2023-06-06T16:00:20.000Z
- Updated: 2023-06-06T16:00:20.000Z
- Author: Sara Burke

Here's an easy method to block specific HTTP request methods on endpoints created automatically by Spring Data REST. This example blocks POST and DELETE. This obviates any changes or overrides in your repository layer.

Note: You should probably [do this](https://stackoverflow.com/a/42516244?ref=saraburke.net) instead, but if you don't want to mess with your interface, here's another way.

```java
@RepositoryRestController
@ExposesResourceFor(YourEntity.class)
@RequiredArgsConstructor
public class YourEntityController {

  @PostMapping("/endpoint")
  HttpEntity<?> post() {
    return new ResponseEntity<>(HttpStatus.METHOD_NOT_ALLOWED);
  }

  @DeleteMapping("/endpoint/{id}")
  HttpEntity<?> delete(@PathVariable String id) {
    return new ResponseEntity<>(HttpStatus.METHOD_NOT_ALLOWED);
  }

}

```