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?
Using Postman REST Client, you can easily debug REST APIs. Postman REST API comes with a very easy-to-use user interface with which you just need Postman installed on your PC. You can access your files anytime and anywhere, which makes the entire process easier.
Postman is an application used for API testing. It is an HTTP client that tests HTTP requests, utilizing a graphical user interface, through which we obtain different types of responses that need to be subsequently validated.
To send a path parameter, enter the parameter name into the URL field, after a colon, for example :id . When you enter a path parameter, Postman will populate it in the Params tab, where you can also edit it.
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.
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