Using CURL to test HTTP Requests

$ curl -i -X POST -H "Content-Type:application/json"-d '{ "firstName" : "Frodo", "lastName" : "Baggins" }' http://localhost:8080/people
/1.1201CreatedServer:Apache-Coyote/1.1Location: http://localhost:8080/people/1Content-Length:0Date:Wed,26Feb201620:26:55 GMT

  • -i ensures you can see the response message including the headers. The URI of the newly created Person is shown
  • -X POST signals this a POST used to create a new entry
  • -H "Content-Type:application/json" sets the content type so the application knows the payload contains a JSON object
  • -d '{ "firstName" : "Frodo", "lastName" : "Baggins" }' is the data being sent

admin has written 55 articles