Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does delete operation work with Rest in Spring Data

Currently we have exposed our methods like this

@RestController
@RequestMapping("/app/person")
public class PersonResource {

    @Timed
    public void delete(@PathVariable Long id) {
        log.debug("REST request to delete Person: {}", id);
        personRepository.delete(id);
    }
}

The operations of this method, in terms of input and output, are very clear to the user developer.

This article http://spring.io/guides/gs/accessing-data-rest/ shows how to expose JPARepositories directly obviating the need of a service layer.

@RepositoryRestResource(collectionResourceRel="people", path="people")
public interface PersonRepository extends JpaRepository<PersonEntity, Long> {

}

It is not obvious to me how I can make a "delete operation" available with PathVariable Long id.

There is an excellent article on this topic. https://github.com/spring-projects/spring-data-rest/wiki/Configuring-the-REST-URL-path But it actually shows how to supress export of a delete operation.

like image 963
user721025 Avatar asked May 03 '26 15:05

user721025


1 Answers

As documented here, Spring Data REST will expose item resources for the repository you declare. Thus, all you need to do is discover the URI of the resource to delete and issue a DELETE request to it.

like image 152
Oliver Drotbohm Avatar answered May 05 '26 10:05

Oliver Drotbohm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!