Support for returning response bodies on deletion of item resources.
RepositoryRestConfiguration now allows to configure to return a response body for the deletion of item resources. The controller implementation follows the same patter we have already established for creation and updates: unless explicitly enabled or disabled we now consider the presence of an accept header as indicator of whether a response body should be rendered. This could be a "breaking" change for clients having explicitly expected 204 until now even for requests with an Accept header. If that's an issue, those should either explicitly disable the setting, do not submit an Accept header or loosen their expectations to expect either 200 or 2xx as indicator of success in general. Fixes #2225.
This commit is contained in:
@@ -402,7 +402,9 @@ class RepositoryEntityController extends AbstractRepositoryRestController implem
|
||||
*/
|
||||
@RequestMapping(value = BASE_MAPPING + "/{id}", method = RequestMethod.DELETE)
|
||||
public ResponseEntity<?> deleteItemResource(RootResourceInformation resourceInformation, @BackendId Serializable id,
|
||||
ETag eTag) throws ResourceNotFoundException, HttpRequestMethodNotSupportedException {
|
||||
ETag eTag, PersistentEntityResourceAssembler assembler,
|
||||
@RequestHeader(value = ACCEPT_HEADER, required = false) String acceptHeader)
|
||||
throws ResourceNotFoundException, HttpRequestMethodNotSupportedException {
|
||||
|
||||
resourceInformation.verifySupportedMethod(HttpMethod.DELETE, ResourceType.ITEM);
|
||||
|
||||
@@ -419,7 +421,9 @@ class RepositoryEntityController extends AbstractRepositoryRestController implem
|
||||
invoker.invokeDeleteById(entity.getIdentifierAccessor(it).getIdentifier());
|
||||
publisher.publishEvent(new AfterDeleteEvent(it));
|
||||
|
||||
return new ResponseEntity<Object>(HttpStatus.NO_CONTENT);
|
||||
return config.returnBodyOnDelete(acceptHeader)
|
||||
? ResponseEntity.ok(assembler.toFullResource(it))
|
||||
: new ResponseEntity<Object>(HttpStatus.NO_CONTENT);
|
||||
|
||||
}).orElseThrow(() -> new ResourceNotFoundException());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user