Menu
Coddy logo textTech

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/3

And when in doubt, point it at a listener and read the request back.

challenge icon

Challenge

Put the whole chapter into one request.

  1. Start the capture listener on port 9127
  2. Send a PUT to http://127.0.0.1:9127/users/3 with the JSON body {"role":"admin"}, correctly labelled
  3. 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

Terminal
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Networking with the Terminal

Practice on your own: Terminal playground