Using Postman to test REST persistence endpoints

2019-02-17 13:18发布

问题:

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?

回答1:

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

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.