14

I want send path variable in post mapping, in postman software.I select post mapping body and then how to do? I checked with @RequestParam vs @PathVariable example,all answers for get method, But I need answer for post method.

@RestController
@RequestMapping("api/v1/customers") 
public class CustomerController {

@PostMapping("/{code}")
    public String postRequest(@PathVariable String code,@RequestBody CustomerDTO dto){
         System.out.println(dto);
         System.out.println(code);
         return "Something";
    }
}
Dumidu Udayanga
  • 864
  • 2
  • 9
  • 21

3 Answers3

44

the easy way to put a path variable in Postman is your case is "/:code"

check link to see how to add path variables in Postman

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
szyjek
  • 581
  • 1
  • 4
  • 5
12

enter image description here

select post -> add the url -> select body -> choose raw -> select JSON(application/json) -> add your json data -> click send

baba
  • 265
  • 3
  • 9
  • 4
    what you have shown in the picture is POST body, but the question is asking about Path variable. Your answer is not relevant to the actual question asked. – Muhammad Tariq Apr 03 '22 at 16:28
3

You can refer official documentation :

https://www.getpostman.com/docs/v6/postman/sending_api_requests/requests

Please go to charpter URL .

Some API endpoints use path variables. You can work with those in Postman. Below is an example of a URL with a path variable:

https://api.library.com/:entity/

To edit the path variable, click on Params to see it already entered as the key. Update the value as needed. For example, :entity can be “user” in this specific case. Postman also gives you suggestions to autocomplete the URL.

Mykhailo Moskura
  • 2,073
  • 1
  • 9
  • 20