I am trying to create java
code to delete an item from a repository in a spring boot
server using the item's ID.
My server code:
@DeleteMapping("/deleteUser/{id}")
public void deleteUser(@PathVariable Long id){
userRepository.deleteById(id);
}
Java client code to connect to server:
URL url = new URL("http://localhost:1234/deleteUser");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("DELETE");
conn.setRequestProperty("Content-Type", "application/json");
For my other requests of get
and post
I would use the output stream to write to the server, but I am not sure the exact code to send the ID that needs to be deleted to the server