Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Postman to test REST persistence endpoints

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?

like image 416
skyman Avatar asked Apr 13 '16 11:04

skyman


People also ask

Can Postman BE USED FOR REST API?

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.

Can Postman be used for testing?

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.

How do you give path parameters in Postman?

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.


1 Answers

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.

like image 85
asg Avatar answered Oct 17 '22 12:10

asg