DEV Community

Cover image for CURL Command Explained
Manmeet Singh
Manmeet Singh

Posted on • Originally published at thatsmanmeet.com

CURL Command Explained

In today's world, we mostly use Client-Server Architecture, which means multiple clients connect to a centralized server. Of course, there can be multiple servers and distributed systems too, but to understand the Curl command, we'll focus on one client and one server.

Before we dive into the cURL command and how it works, let's first understand the client-server architecture.

What is Server?

A server is a computer system that is always connected to the Internet, listening for incoming requests, and providing appropriate responses.

There are different types of servers, such as application servers, database servers, and mail servers.

Servers play a crucial role in the client-server architecture by ensuring that clients receive the necessary data and services they request. Understanding how servers work helps us use tools like cURL more effectively to interact with these systems.

What is a Client?

A client is anything a user controls, from a web browser to a terminal, that can send requests to a server and receive responses to display to the user.

A client can be a web browser like Chrome or Firefox, an API testing tool like Postman or Bruno, or terminal software like cURL.

Client-Server Architecture

Client Server Architecture

Client Server Architecture simply says that a client will send a request using REST API (or any other API) to the server, the server will process the request and will send the response appropriately to the client.

Request will contain information such as the route (URL Path), HTTP Method (POST, GET, etc), Headers (e.g. content-type) and the body, which will contain the payload or any data, that is required by the server to perform the operations.

Response will also contain information such as the HTTP Status (e.g 200, 201), implying the result of operation, Response Headers (e.g. content-type) and the body which is the payload, that will tell the client about the status of the operation.

We will not dive deep into more things but just keep in mind that client sends request to the server and server provides the response. Now let’s proceed to our main topic cURL.

What is cURL

cURL is an utility or an software that allows us to send an request to the server, receive the response and show the data appropriately inside the terminal.

It can also upload and download files from the web servers and also support multiple protocols such as FTP, SMTP, Telnet and more, hence making this a really powerful utility for connecting with servers.

Why Programmers loves cURL

Well, there’s many reasons programmers love cURL command and many even like using this command over other software.

  1. No Installation needed: For many programs such as Postman or Chrome, they need to be installed on the OS, but cURL usually comes pre-installed on all modern OS, making it much easier to switch to any OS and start working immediately from the terminal using cURL.
  2. Great for No-GUI environments: Many times when working on servers, we don’t have access to GUI programs and this is where the cURL utility really shines. It doesn’t have any fancy UI and can work from the terminal as CLI application.
  3. Lightweight: cURL is a very lightweight software unlike other clients such as chrome or postman.
  4. Multiple Protocol Support: cURL supports multiple protocols which clients like chrome don’t and with option to upload/download files from server as well, really makes it a great utility.

Now, that we understood what is cURL and why programmers love it. You might be thinking; “Hmm, okay but then why we learned the client-server architecture first?”

Well, because, now we are going to learn the cURL commands and try sending headers, payloads and other information as well.

Basic cURL Commands

Let’s understand some basic cURL commands, that we can use in our everyday life as developers.

Fetch the Webpage

To fetch the webpage from the a server, we can use the command:

curl https://google.com
Enter fullscreen mode Exit fullscreen mode

Response we got from the server was:

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="https://www.google.com/">here</A>.
</BODY></HTML>
Enter fullscreen mode Exit fullscreen mode

So, you can see that the server replied us with 301 status code with message document was moved. This happens because the basic cURL command will not follow up with the redirects.

We can use -L flag which means follow redirects

curl -L https://google.com
Enter fullscreen mode Exit fullscreen mode

Response we get from the server was:

Curl Terminal

Hence the -L flag will follow the redirects and will print the entire HTML code from the webpage on the terminal.

View the Response Headers

Headers are sent by the server as the response. To view the headers we can use -I flag.

curl -I https://google.com
Enter fullscreen mode Exit fullscreen mode

Response we get from the server is:


 ~/Developer/cohort/curl/ curl -I https://google.com
HTTP/2 301
location: https://www.google.com/
content-type: text/html; charset=UTF-8
content-security-policy-report-only: object-src 'none';base-uri 'self';script-src 'nonce-B_J2kdosi1cTamYOJzeVxg' 'strict-dynamic' 'report-sample' 'unsafe-eval' 'unsafe-inline' https: http:;report-uri https://csp.withgoogle.com/csp/gws/other-hp
date: Tue, 27 Jan 2026 12:40:23 GMT
expires: Thu, 26 Feb 2026 12:40:23 GMT
cache-control: public, max-age=2592000
server: gws
content-length: 220
x-xss-protection: 0
x-frame-options: SAMEORIGIN
alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
Enter fullscreen mode Exit fullscreen mode

You can see the headers that was sent by the server as response to our client, being shown in the terminal. However these are only the headers, if you want to see Headers + Response, then use the -i flag.

curl -i https://google.com
Enter fullscreen mode Exit fullscreen mode

Response we get from the server is:

 ~/Developer/cohort/curl/ curl -i https://google.com
HTTP/2 301
location: https://www.google.com/
content-type: text/html; charset=UTF-8
content-security-policy-report-only: object-src 'none';base-uri 'self';script-src 'nonce-1k2aoSXbjjeLVNgA55J97A' 'strict-dynamic' 'report-sample' 'unsafe-eval' 'unsafe-inline' https: http:;report-uri https://csp.withgoogle.com/csp/gws/other-hp
date: Tue, 27 Jan 2026 12:42:23 GMT
expires: Thu, 26 Feb 2026 12:42:23 GMT
cache-control: public, max-age=2592000
server: gws
content-length: 220
x-xss-protection: 0
x-frame-options: SAMEORIGIN
alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="https://www.google.com/">here</A>.
</BODY></HTML>
Enter fullscreen mode Exit fullscreen mode

From the above response, you can see that the Headers are being displayed along with the response sent by the server.

Send Request Headers to the server

We have seen the response headers, that server send as the response. However, we can also send some headers from our client to the server.

We can use -H flag followed by Header-Name: value along with our cURL command to the server.

 curl -H "content-type:application/json" https://google.com
Enter fullscreen mode Exit fullscreen mode

Receive Payload from the Server

As seen from our client-server architecture, we can receive, the payload from the server. We can specify the HTTP method using -X flag, followed by the HTTP method such as GET, POST etc.

curl -X GET https://jsonplaceholder.typicode.com/posts/1
Enter fullscreen mode Exit fullscreen mode

Response we get from the server is:

 ~/ curl -X GET https://jsonplaceholder.typicode.com/posts/1
{
  "userId": 1,
  "id": 1,
  "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
  "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
}
Enter fullscreen mode Exit fullscreen mode

You can see the payload we received from the server.

Send Payload to the Server

To send some data (payload) to the server, we can use the POST method. We can also pass headers using -H flag and data using -d flag if necessary.

# make sure they are in same line, I just seperated them to make it more visible
curl -X POST \
  -H "content-type: application/json" \
  -d '{"name": "Manmeet", "role": "admin"}' \
  https://jsonplaceholder.typicode.com/users
Enter fullscreen mode Exit fullscreen mode

Response I get from the server was:

 ~/ curl -X POST -H "content-type: application/json" -d '{"name" : "Manmeet", "role":"admin"}' https://jsonplaceholder.typicode.com/users
{
  "name": "Manmeet",
  "role": "admin",
  "id": 11
}
Enter fullscreen mode Exit fullscreen mode

Here, you can see that the data included my name and role as manmeet and admin, which the server acknowledged and sent me as a response for the confirmation, that my data was received by server.

You can also use other methods such as PUT, PATCH, OPTIONS, DELETE as well.

Filtering Data with Query Parameters

Sometimes, you don't want the server to send back everything. You might want to filter the data, limit the number of results, or sort them. In Client-Server architecture, we usually handle this by passing Query Parameters directly in the URL.

Query parameters start with a ? after the URL path. Multiple parameters can be separated by the ampersand & symbol, like /users?_limit=5&search=A.

Let's say we want to fetch posts from the server, but we only want the top 5 results, and specifically for user ID 1. We can combine these using parameters provided by the JSONPlaceholder API.

curl "https://jsonplaceholder.typicode.com/posts?_limit=5&userId=1"
Enter fullscreen mode Exit fullscreen mode

The server will return an array containing only 5 post objects that belong to User 1, rather than the full list.

Downloading Files (-o)

Sometimes the response isn't text as it could be a massive JSON, an image, or a zip file. Printing this response to server will cause a mess, making it harder to understand.

Use the -o (output) flag to save the response to a file.

# Save the Google homepage source code to a file named 'google.html'
curl -o google.html https://www.google.com
Enter fullscreen mode Exit fullscreen mode

Above command will create a new file google.com and will print the source code of google.com webpage inside it.

Debugging with Verbose Mode (-v)

As a developer, things will break. Maybe your API returns a 500 Error, or your authentication fails. This is where curl becomes a diagnostic tool.

The -v (verbose) flag tells cURL to show the entire conversation—the handshake, the hidden headers, and the raw traffic.

curl -v https://google.com
Enter fullscreen mode Exit fullscreen mode

Understanding the Output:

  • Lines starting with * show the connection process (DNS resolution, SSL handshake).
  • Lines starting with > are the data you sent (Request).
  • Lines starting with < are the data received (Response).

This gives you "X-Ray vision" into the HTTP protocol.

Conclusion

We started this journey understanding the Client-Server Architecture because tools are useless if you don't understand the system they interact with. We then moved to cURL, exploring how to fetch pages, inspect headers, and send data using methods like POST. While graphical tools hide the complexity, cURL forces you to understand the raw HTTP protocol. It makes you think about headers, payloads, and status codes. This doesn't just make you better at using the command line; it makes you a better Backend Developer.

Top comments (0)