J
J
Jypsy2019-01-29 20:30:38
Java
Jypsy, 2019-01-29 20:30:38

Why does the request not see the body?

There is a Delete controller that throws an error and does not want to delete the user by body.

@DeleteMapping("*/deleteoneusers")
    public void deleteUsers(@RequestBody User user) {
        userRepository.delete(user);
    }

5c508cb5eab85166498646.png5c508d04844b9991300934.png
I send the user body that comes with the get request.
What's the matter, why does it say that the request body is empty?
Same thing with this controller
5c508db37f718738611826.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2019-01-29
@Jypsy

According to the standard, delete requests cannot have a body - RFC 7231 .

A
alfss, 2019-01-29
@alfss

because you are sending an array and expecting one element.
and it is not yet clear which content-type is set.
Why the whole object at all, when id is enough for deletion?

@DeleteMapping("/users/{id}")
void deleteUser(@PathVariable Long id) {
  repository.deleteById(id);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question