Default operation is a GET:
curl http://api.example.com/statuses/1234
Use square brackets with a dashed range:
curl http://api.example.com/items/[1000-2000]
Use curly braces with comma-delimited strings:
curl http://api.example.com/produxts/{abc,def,ghi}/status
Use the header option: -H
or --header
curl -H 'Accept: application/json' http://api.example.com/items/1234
Use multiple -H options:
curl -H 'Accept: application/json' -H 'Accept-Encoding: gzip' http://api.example.com/items/1234
Use the verbose option: -v
or --verbose
curl -v http://api.example.com
To send data to the server, you use either POST or PUT, depending on what the API requires. To do a POST, you simply use the -d
(--data
) with some content
curl -d "name=Ted" http://api.example.com:8080/customers
Note that this uses application/x-www-from-urlencoded
as the Content-Type, i.e., as if it was submitted by an HTML Form. You can use multiple -d
optinos, which will be combined, e.g., these two commands produce the same content:
curl -d "first=Ted" -d "last=Young" http://api.example.com/customers
curl -d "first=Ted&last=Young" http://api.example.com/customers
If you want to send JSON, you'll need to specify the Content-Type explicitly using the -H (header) option:
curl -d '{"name": "Ted"}' -H 'Content-Type: application/json' http://api.example.com/items
##PUT data to a URI
curl -X put -d '{"name": "Ted"}' -H 'Content-Type: application/json' http://api.example.com/items
##Http authentication
curl -u username:password http://api.example.com/items
##Cookie
curl -b 'id:1234' http://example.com/items
##Limit rate
curl --limit-rate 10K www.far-away-site.com
##Ignore ssh
curl -i www.not-secure-test-site.com