Learn

In addition, we can make POST requests using the curl command. Let’s again imagine that we are adding Charlie the German Shepherd as a dog intake patient for our imaginary pet clinic. We would use this curl syntax:

curl -X POST -d "{\"name\":\"Charlie\", \"breed\":\"German Shepherd\"}" -H "Content-Type: application/json" http://www.mypetclinic.com/dogs/
  • -X POST tells the server that the client is making a POST request, where -X is the curl parameter specifying the type of request method to use.
  • -d (short for --data) indicates to the server that the client is sending new data to an existing application.
  • The content inside "{ }", \"name\":\"Charlie\", \"breed\":\"German Shepherd\" , is the data that the client wants to send (as indicated by the preceding -d). We use the {\"key1\":\"value1\", \"key2\":\"value2\"} syntax, where name and breed are the names of the two keys that define the dog object, and “Charlie” and “German Shepherd” are the values corresponding to those keys respectively.
  • -H "Content-Type: application/json" specifies that we are sending data in JSON format.
  • Finally, the URL http://www.mypetclinic.com/dogs/ tells the server where to send this new data. In this case, the newly-created dog object will be posted under the dogs resource.

Instructions

1.

Hit the POST endpoint with this curl command:

curl -X POST -d "{\"name\":\"Pizza Hut\", \"line1\":\"123 Main St.\", \"city\":\"San Diego\", \"state\":\"CA\", \"zipCode\":\"90029\"}" -H "Content-Type: application/json" http://localhost:4001/restaurants/

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?