xory.dev

Useful curl flags for HTTP requests

curl

As curl is a powerful tool, it also has many flags. According to ChatGpt, it has over 240 options. However, most are not useful for everyday tasks.

Below is a cheat sheet of the most common flags with simple examples:

-d, --data <data> - to add add to POST body

curl --data "ok" https://example.com

-F, --form <name=content> to POST content as Content-Type multipart/form-data

curl --form "key=value" https://example.com

-X, --request <method> - to specify HTTP method.

curl -X GET https://example.com

-H, --header <header/@file> - to add headers

curl -X GET https://example.com

-i, --include - include headers in the response

curl -i https://example.com

-u, --user <user:password> - to pass data for basic authentication

curl -u "user:pass" https://example.com

--json <data> - to post data as JSON, automatically added Content-Type application/json

curl --json '{"key":"value"}' https://example.com