Posted In: cURL, Spring, Spring REST

How to POST JSON data with Curl from Terminal/Commandline to Test Spring REST?

cURL

@RequestMapping(value = "/employee/{employeeId}",
          method = { RequestMethod.GET })
  public @ResponseBody Object getEmployee(ServletRequest req,
          ServletResponse res,
          @PathVariable("employeeId") int employeeId)

curl -H “Content-Type: application/json” -X GET http://localhost:83/Example201711/employee/2
@RequestMapping(value = "/employee",
          method = { RequestMethod.POST })
  public @ResponseBody Object insertEmployee(ServletRequest req,
          ServletResponse res, @RequestBody String requestJson)		  

curl 
-H “Content-Type: application/json” 
-X POST 
-d {\”firstName\”: \”Abhijit\”,\”lastName\”: \”Penekar\”,\”emailId\”: \”a@a.com\”} 
http://localhost:83/Example201711/employee
@RequestMapping(value = "/employee",
          method = { RequestMethod.PUT })
  public @ResponseBody Object updateEmployee(ServletRequest req,
          ServletResponse res, @RequestBody String requestJson)	

curl 
-H “Content-Type: application/json” 
-X PUT 
-d {\”employeeId\”:2,\”firstName\”: \”Abhijit\”,\”lastName\”: \”Penekar\”,\”emailId\”: \”a@a.com\”} 
http://localhost:83/Example201711/employee
@RequestMapping(value = "/employee",
          method = { RequestMethod.DELETE })
  public @ResponseBody Object deleteEmployee(ServletRequest req,
          ServletResponse res, @RequestBody String requestJson)		  

curl 
-H “Content-Type: application/json” 
-X DELETE 
-d {\”employeeId\”:2} http://localhost:83/Example201711/employee
  @RequestMapping(value = "/employee/list",
          method = { RequestMethod.POST })
  public @ResponseBody Object getEmployeeList(ServletRequest req,
          ServletResponse res, @RequestBody String requestJson)

curl -H “Content-Type: application/json” 
-X POST 
-d {} http://localhost:83/Example201711/employee/list

by , on July 11th, 2017

  • Categories