Code: Select all
GET --> Ok
POST -> Created
PUT --> Ok ???
DELETE --> NoContent ???
Welche Statuscodes sollte ich also für PUT und DELETE verwenden? Hier ist ein Beispiel für die Verwendung von DELETE, aber ich bin mir nicht sicher, ob wir den Textkörper zurückgeben können, wenn der Statuscode „NoContent“ ist (ist das sinnvoll?)
Code: Select all
@DeleteMapping("/categories/{id}")
public ResponseEntity deleteById(@PathVariable long id) {
final CommandResponse response = categoryService.deleteById(id);
return ResponseEntity
.status(HttpStatus.NO_CONTENT)
.body(new ApiResponse(Instant.now(clock).toEpochMilli(), SUCCESS, response));
}
#1:
Code: Select all
@DeleteMapping("/categories/{id}")
public ResponseEntity deleteById(@PathVariable long id) {
categoryService.deleteById(id);
return ResponseEntity.ok(new ApiResponse(Instant.now(clock).toEpochMilli(), SUCCESS));
}
Code: Select all
@DeleteMapping("/categories/{id}")
public ResponseEntity deleteById(@PathVariable long id) {
categoryService.deleteById(id);
return ResponseEntity
.status(HttpStatus.NO_CONTENT)
.build();
}
 Mobile version
 Mobile version