DEV Community

Cover image for Curl Command for Developer
Ar-ruk Kachen
Ar-ruk Kachen

Posted on

Curl Command for Developer

This cheatsheet was collected famous CURL command for Software Developer. Exactly it's easy for checking and testing communicate between frontend and backend

if you want to see more information or option. Please see in : Curl man page

1.Request with set value specific header

curl --header "X-MyHeader: 123" URL
Enter fullscreen mode Exit fullscreen mode

2.Request with using cookie

curl -v --cookie "COOKIEKEY=VALUE" URL
Enter fullscreen mode Exit fullscreen mode

3.Request with method and body

curl -X HTTPMETHOD -H "Content-Type: application/json" -d '{"key1":"value"}' URL

Enter fullscreen mode Exit fullscreen mode

4.Request with Form-data

curl -X POST -H "Content-Type: multipart/form-data;" -F "key1=val1" URL

Enter fullscreen mode Exit fullscreen mode

5.Request with Post File

curl -X POST -F 'file=@/file-path.csv' URL

Enter fullscreen mode Exit fullscreen mode

6.Get HTTP Status Only

curl -s -o /dev/null -w "%{http_code}" URL

Enter fullscreen mode Exit fullscreen mode

7.Get Response Header only

curl -I https://www.google.com

Enter fullscreen mode Exit fullscreen mode

8.Get Response value of specific header

(Example: for get content-type header)

curl -sI URL | tr -d '\r' | sed -En 's/^<u>content-type</u>: (.*)/\1/p'

Enter fullscreen mode Exit fullscreen mode

Discussion (0)