CURL Must Know Commands for Web Developers


As a web developer, you need to interact with APIs/URLs all day. There are many ways you can interact with such resources and get the job done. However, knowing how to CURL can boots your productivity to another level.

In this post, I’m going to show you the most useful CURL commands you can use right now to help you become a more effective developer.

Let’s get started.

Basic CURL commands

Here are some commands to get your feet wet:

Sending GET requests

The default HTTP method curl uses is GET. Thus, to send a GET request to an URL, you only need to call curl with that URL:


You will see a lot of text on the screen. This is the HTML content of

Save request body to a file

If you want to save the body of the request to a local file, use this:

curl -o github.html

Here, I save the HTML content of to a local file named github.html.

Follow redirects

If you make a GET request to, you will not see the content you would when visiting it in the browser.

CURL not following redirect on http
curl on http (not SSL) github URL returned empty

This is because the http endpoint redirects to https.

To tell curl to follow any redirects, you need to use -L

curl -L

You would see the output exactly likes when you query https directly.

More advanced curl queries

Now you know the basic of curl usage, let’s try some slightly advance commands.

Send a request with headers

You can specify the request headers with -H option. One of the most common use cases of passing a header passing JWT token for authorization.

In such case, you would send this command:

curl -H 'Authorization: Bearer'

If you have multiple headers, simply declare multiple -H options.

Specify the HTTP method

As mentioned above, the default HTTP method curl uses is GET. If you want to use other methods, specify it with -X. Remember, there is only one method per request.

# Sending post
curl -X POST

# Sending PUT
curl -X PUT

Query URL with basic auth

Basic Authen is a simple authentication mechanism you can use to access secured endpoints. To make requests to such endpoints using basic auth, you can use the following command:

# Sending post
curl -X POST -u username:password

POST JSON data to an endpoint

You can use the following command to send data to and endpoint using POST (PUT/PATCH are similar, you just need to replace the verb).

# Sending post
curl -X POST -H "Content-Type: application/json" -d '{"param1": "value1", "param2": "value2"}'

To send form data, you can use the following command:

# Sending post
curl -X POST -d 'username=johndoe&password=secret'

Other useful CURL commands

By default, curl output is not verbose. You can add -v to get more info about the request:

curl -v

If you are in development and use a self-sign certificate, chances are you will have curl error (60). To bypass SSL check, use -k option:

curl -k


In this post, I’ve shown you how to use CURL to effectively communicate with URLs and API endpoints. Knowing how to use CURL has proven very beneficial for me in my day-to-day work as a web developer. I believe you would get the same benefits too.

Leave a Comment