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?
As your @RequestBody
is primitive so you have to send just simple number in body. Following snap of request body using POSTMAN
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With