0

For my project requirement, I created an API in JAVA which accepts 2 parameters like below

getSimilarImages(@PathParam("rbcCode") String rbcCode, List<String> fieldNames)

I am new to POSTMAN application.

Could anyone educate me on how do I call this API using POSTMAN.

Below is my controller file code.

@Controller
@Path("/services/AIMLServices")
public class AIMLController {

private static Logger LOG = LogManager.getLogger(AIMLController.class);

@Autowired
AIMLService aimlService;

@POST
@Path("/getSimilarImages/{rbcCode}")
@Produces(MediaType.APPLICATION_JSON)
public String getSimilarImages(@PathParam("rbcCode") String rbcCode, List<String> fieldNames) {
    LOG.info("IN getSimilarImages() API");
    System.out.println("IN getSimilarImages() API rbcCode=" + rbcCode + " No of fields=" + fieldNames.size());
    return aimlService.getSimilarImages(rbcCode, fieldNames).toString();
}

}

I tried with this below setup in POSTMAN,

Doing a post call with the below URL by passing rbcCode
http://localhost:4990/dev/acs/admin/fm/api/services/AIMLServices/getSimilarImages/BELK

And under Body raw type as JSON, I am passing list like below
["a","b","c"]

but it did not work.

9
  • what the response in postman ? Commented Oct 3, 2019 at 10:06
  • have you tried adding rbcCode in your path? like @Path("/getSimilarImages/{rbcCode}") Commented Oct 3, 2019 at 10:07
  • have you tried @RequestBody annotation for your list of strings? Commented Oct 3, 2019 at 10:10
  • Can you screenshot your postman and share all settings you have done? Commented Oct 3, 2019 at 10:14
  • tried, that too not working Commented Oct 3, 2019 at 10:26

1 Answer 1

1

I believe you need to add @ResponseBody on your method and use @RequestBody for your list parameter.

Also as others mentioned, you need to specify your path param in the @Path

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks @madz and everyone, I am able to call the api now after adding RequestBody and Consumes
@Aadi Cheeersss

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.