Recap: Writing Data
Lesson 37 of 47 in Coddy's Networking with the Terminal course.
Sending data comes down to three decisions.
Which method. -d makes it a POST automatically; -X sets anything else. POST submits, PUT stores at a location, DELETE removes.
What the body is. -d 'a=1&b=2' for form data, a JSON string for an API. Use --data-urlencode for anything a human typed.
How you label it. curl says form encoded unless you say otherwise, so JSON needs -H 'Content-Type: application/json'. Forgetting it is the most common mistake in this chapter.
curl -s -X PUT -H 'Content-Type: application/json' \
-d '{"role":"admin"}' http://127.0.0.1:9127/users/3And when in doubt, point it at a listener and read the request back.
Challenge
Put the whole chapter into one request.
- Start the capture listener on port 9127
- Send a PUT to
http://127.0.0.1:9127/users/3with the JSON body{"role":"admin"}, correctly labelled - Print the request line, then the Content-Type line, then the body
Expected output:
PUT /users/3 HTTP/1.1
Content-Type: application/json
{"role":"admin"}Try it yourself
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Networking with the Terminal
4Is It Reachable?
ICMP and pingReading Ping OutputWhen Ping LiesRefused or Timed OutRecap: Reachability7Sending Data
POST with -dWhat -d Actually SendsForm EncodingSending JSONPUT and DELETERecap: Writing DataPractice on your own: Terminal playground