curl

curl CLI tool

Usage

  • -X, --request: request method (e.g. POST, PUT)
  • -N, --no-buffer: used to disable buffering of output stream, can use when expecting stream that you want to view live
  • -d, --data <data>: send specified data in POST request

Basic Requests

GET

POST application/json

curl -d '{"key1":"value1", "key2":"value2"}' -H "Content-Type: application/json" -X POST[http://localhost:3000/data](http://localhost:3000/data)

POST to streaming endpoint

curl -d '{"json":"string"}' -H "Content-Type: application/json" -X POST -N http://localhost:5000/api/path

Download Files

curl [http://some.url](http://some.url/) --output some.file

Redirects

I often run into the issue of trying to remotely download a file (Github releases are a common example) but the known URL is not the actual endpoint for a file. Here you can use curl -JLO <url> to ensure curl follows the redirect(s) until it eventually gets to the target file.

Sources