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?

1

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.