Reputation: 774
I need to add and expose the custom delete method to the spring data rest repository. How is it possible to specify DELETE method, because by default spring-data-rest exposes it like GET.
@RepositoryRestResource(path = "documents")
public interface DocumentRepository extends JpaRepository<DocumentEntity, Long> {
void deleteByDate(@Param("date") LocalDate date);
}
Upvotes: 1
Views: 249
Reputation: 23226
The method you have added will be considered a 'Search' resource (as can be seen from the exposed path /documents/search/deleteByDate?...
) and as the documentation notes:
5.5.1. Supported HTTP Methods As the search resource is a read-only resource, it supports only the GET method.
Solution then is to create a standard Spring MVC controller to handle this custom action:
@DeleteMapping("/documents/deleteByDate")
public ResponseEntity<> deleteDocumentByDate(@RequestParam("date") LocalDate date){
....
}
Upvotes: 1