0

I want to implement endpoint for deleting a list if IDs

    @DeleteMapping("/contracts/remove/{id}")
    public ResponseEntity<?> remove(@PathVariable Integer id) {     
        contractsTerminalsService.delete(id);        
        return ResponseEntity.noContent().build();
    }

How I can send a list of IDs like this:

POST /api/contracts/bulk_delete
with body { ids: [1,5,6] }

What is the proper way to implement this?

Peter Penzov
  • 1,126
  • 134
  • 430
  • 808

1 Answers1

2

Just use List<Integer> and your request should be like /api/contracts/bulk_delete/1,5,6

@DeleteMapping("/contracts/bulk_delete/{ids}")
public ResponseEntity<?> remove(@PathVariable List<Integer> ids) {     
    // Do whatever you want with id        
    return ResponseEntity.noContent().build();
}

For more reference visit Passing an Array or List to @Pathvariable - Spring/Java

Sudhir Ojha
  • 3,247
  • 3
  • 14
  • 24