Reputation: 715
in Spring, is it possible to eg. POST
single object to controller with @RequestBody
?
Something like this:
@RequestMapping(value = "/users", method = RequestMethod.POST)
public ResponseEntity<Void> createUser(@RequestBody Long userId) {
// do smth with userId
}
If yes, what should json
body look like?
Upvotes: 9
Views: 9447
Reputation: 2447
As your @RequestBody
is primitive so you have to send just simple number in body. Following snap of request body using POSTMAN
Upvotes: 12
Reputation: 16465
It is absolutely possible.
This is a curl command that gets back a Http 200 for the above said end point
curl -v http://localhost:8080/users -X POST --header "Content-Type:application/json" -d "123"
Data is just a string literal "123"
Upvotes: 2