I am a newbie in using Postman for testing RESTful endpoints in Spring applications. Until now I only invoked simple methods, without parameters, which return only some String messages. I also read some topics about invoking methods that have parameters of basic types (int, String). Currently I have to create a Spring project for searching some jobs data stores in a Postgres DB. The controller method is this:
@ApiOperation(value = "Search job", notes = "With this request you can search for jobs", authorizations = {@Authorization(value = "Bearer")})
@PostMapping("/search")
public ResponseEntity<?> search(@RequestBody JobSearchEntity searchCriteria) {
log.info("JobsController -> search method");
//JobSearchEntity jobSearchEntity = modelMapper.map(jobSearch, JobSearchEntity.class);
List<JobEntity> jobs = jobService.searchJobs(searchCriteria);
//log.info(String.format("Job found: %s ", jobSearch));
return ResponseEntity.ok(jobs);
}
As it can be seen, it takes as parameter an object of a custom-designed class from my project, which is shown below:
@Data
public class JobSearchEntity {
private String jobTitle;
private String jobDescription;
private List<String> technology;
private List<String> programmingLanguage;
private List<String> jobMobility;
private List<String> jobType;
private Integer paymentMin;
private Integer paymentMax;
}
Does someone please tell me how can I test such a method with Postman (or even more, is it possible to test such Restful endpoints)?
CodePudding user response:
I'm supposing that your endpoint accepts JSON objects. If so that is quite straightforward.
Go to the body tab of your request and configure it like this:
In the text area below you must insert your "custom" object in JSON format.
e.g:
{
"jobTitle": "test",
"jobDescription": "test",
"technology": ["test"],
"programmingLanguage": ["test"],
"jobMobility": ["test"],
"jobType": ["test"],
"paymentMin": 0,
"paymentMax": 0,
}
CodePudding user response:
Select the body and then select row and then choose JSON. and then write the field of the class which use passed as request body in JSON formate