0

I am tring to call a rest post method from postman. But I am not able to properly set the input parameters for method from postman.

NB : Please dont mark it as duplicate as this dosent have an existing answer in Stackoverflow.

Below the rest API code:

@RequestMapping(value = "/city/village/home", method = RequestMethod.POST)
    @ResponseBody
    public String updateHome(@ModelAttribute final HomeAddress homeAddress,
            final HttpServletRequest request) {

            //// some code ///// 

            }



This is the HomeAddress class

public class HomeAddress{

  public String name;
  public int id;
  public List<String> membersName;


  getters.....
  setters....

  }

Please tell me how to send the request from Postman ?

1 Answer 1

1

If you are using Spring by default your application will be running on localhost:8080 -> then you can use your value /city/village/home -> localhost:8080/city/village/home. You can take a look for example for Spring Boot Controller - https://adityasridhar.com/posts/how-to-create-simple-rest-apis-with-springboot

I'm not sure did you use @Controller annotation on the class and so on... You can see how to use Postman here-> https://adityasridhar.com/posts/how-to-create-simple-rest-apis-with-springboot

You should use Json Format - you can validate it here : https://jsonformatter.curiousconcept.com/

{
  "name": "NAme",
  "id": 5,
  "membersName": [
     "firstName",
    "secondName"
  ]
}
Sign up to request clarification or add additional context in comments.

2 Comments

My doubt is how to call it from postman ? Should i use this Json in the body of the request ?
Yes, you need to put json in the 'Body' sector. In the 'Headers' sector you should put Key -> Content-Type and Value -> application/json

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.