5

I have been trying to build a secured REST endpoint to save (and return) a person object. So far I have a method as below:

@RequestMapping(value = "/save/", method = RequestMethod.POST)
public Person save(@RequestBody Person person) {
    return repository.save(person);
}

I have been trying to use Postman to test this endpoint, but don't seem to be able to structure the URL in the correct way. I should say that I have successfully tested find(Long id) (/find/{id}) and findall.

http://localhost:8080/api/save?person={"id":2,"first":"Brian","last":"Smith"}

First, is this the correct way to structure an endpoint for saving an object, and is the Postman structure correct?

skyman
  • 2,255
  • 4
  • 32
  • 55

1 Answers1

11

Your method is POST. So you should pass on your payload like this.

enter image description here

Also make sure that you have mentioned your web application context root. If api is your context root, then you are correct. But if it is the case then change it to some meaningful name.

asg
  • 2,248
  • 3
  • 18
  • 26