Requests

Send a request with curl

Build GET and POST requests from the command line so you can control methods, headers, and bodies without a browser interface.

curl is an HTTP client you can run in any terminal. I use it daily to check endpoints, reproduce bugs, and script deploy smoke tests.

Fetch a page and show response headers with -i (include headers in output):

curl -i https://flaviocopes.com/

The first line looks like HTTP/2 200. Below it you see headers, then a blank line, then the HTML body.

Send JSON with POST:

curl https://httpbin.org/post \
  -X POST \
  -H 'Content-Type: application/json' \
  -d '{"title":"Learn HTTP"}'

-X sets the method. -H adds a request header. -d supplies a body. When you pass -d, curl defaults to POST, so -X POST is optional here but makes scripts easier to read.

Add -v when something feels off:

curl -v -o /dev/null -s https://flaviocopes.com/

Verbose mode prints DNS, TLS, the outgoing request line, request headers, then response headers. -o /dev/null discards the body so your terminal stays readable. -s hides the progress meter.

Common mistakes I see: forgetting quotes around a URL with & in the query string (the shell splits on &), and sending JSON without Content-Type: application/json so the server parses the body as plain text.

Follow redirects explicitly when you care about the chain:

curl -I -L https://flaviocopes.com/books

-I sends HEAD. -L follows Location headers. You can watch a 301 turn into a final 200.

Save working commands in a script file. I keep a small scripts/smoke.sh on many projects that curls critical URLs after deploy and fails the job if any status is not 2xx.

Try this on your own project: replace the browser for one API call you normally make in DevTools. Rebuild it with curl, then save the command in a scripts/ file for the next time.

Quick check

Result

You got of right.

Lesson completed