cURL HTTP Cheat Sheet

Get

curl <URL>

Send HTTP GET request and view the response

-i prints headers and response
-v prints more verbose, useful for debugging

$ curl -v http://localhost:8085/api/vi/employee/1

Post

curl -d ‘key=value&key=value’ <URL>

Post multiple key values using ‘application/x-www-form-urlencoded’ as content type

$ curl -d ‘param1=value1&param2=value2’ http://localhost:8085/api/vi/employee

curl -F ‘key=value’ -F ‘key=value’ <URL>

Post multiple key values using ‘multipart/form-data’ as content type

$ curl -F ‘param1=value1’ -F ‘param2=value2’ http://localhost:8085/api/vi/employee

curl -d ‘{json}’ -H ‘Content-Type: application/json’ <URL>

Post request with JSON data

$ curl -d ‘{“id”:1,”firstName”:”Adam”}’ -H ‘Content-Type: application/json’ http://localhost:8085/api/vi/employee

curl -F ‘image=@/folder/image.png’ <URL>

Submit form by uploading file, add @ before file location

Put

curl -X PUT <URL>

Send HTTP PUT request

$ curl -X PUT -d ‘param1=value1’ http://localhost:8085/api/vi/employee

Delete

curl -X DELETE <URL>

Send HTTP DELETE request

$ curl -X DELETE http://localhost:8085/api/vi/employee/1

Security

curl -u <userid>:<pass> <URL>

Pass basic authentication details; User id and password

$ curl -u ‘admin:password’ http://localhost:8085/api/vi/employee

curl -k <URL>

Make insecure connection, ignores SSL certification validation