Skip to main content

Command Palette

Search for a command to run...

A Simple Guide to cURL for the Rest of Us

Updated
7 min readView as Markdown
A Simple Guide to cURL for the Rest of Us

If you’re just starting out in the world of programming, you’ve probably heard a lot of fancy words thrown around: API, Server, HTTP. It can feel like everyone else is speaking a secret language.

But here’s the truth: all of programming, especially web stuff, is just about asking for things and getting answers. It’s a conversation.

And today, we’re going to learn how to talk to the internet without a web browser. We’re going to use a simple, powerful tool called cURL.

1. The Big Idea: What is a Server?

Before we talk about cURL, let’s get one thing straight: the internet is just a giant collection of computers called servers.

Think of a server like a super-organized library or a restaurant kitchen.

  • When you type "google.com" into your browser, you are sending a request to the Google server (the library).

  • The server processes your request (finds the book).

  • It sends the answer back to your browser (hands you the book).

Your web browser (Chrome, Firefox, etc.) is like a fancy, visual assistant that handles all this talking for you and then makes the answer look pretty (adds pictures, colors, and buttons).

2. What is cURL (in Very Simple Terms)?

If your browser is the fancy assistant, cURL is the direct messenger like text messages.

cURL (which stands for Client for URLs) is a simple command you type into your terminal (that black screen with text). It lets you send messages directly to a server and get the raw, unfiltered answer back.

Why is this a big deal?

Imagine you’re a chef (a programmer) trying to figure out why a dish (your website) isn't working. You don't want the fancy waiter (the browser) to interpret the message; you want to talk directly to the kitchen (the server) to see the exact ingredients and instructions.

If the browser is so good at talking to servers, why do programmers need cURL?

Browser (Tourist Agency)cURL (Direct Messenger)
Goal: Show you a beautiful, interactive webpage.Goal: Test, debug, and automate data transfer.
What it shows: The final, polished result (HTML, CSS, images).What it shows: The raw data (text, JSON, XML).
Best for: Everyday browsing.Best for: Developers and system administrators.
Analogy: Ordering a meal and having the waiter plate it beautifully.Analogy: Talking directly to the chef about the ingredients and cooking process.

As a programmer, you often need to see the raw ingredients to make sure your code is working correctly. You need to test an API (which we'll get to) without opening a whole browser. cURL is the perfect tool for this quick, raw, and direct communication, because it cuts out the middleman.

Here is the basic flow of what happens:

3. Making Your First Request

Ready to try it? Open your terminal (or command prompt). cURL is pre-installed on almost all modern operating systems (Mac, Linux, and even recent Windows versions).

The simplest command is just the word curl followed by a website address.

console

curl google.com

What happens?

  1. cURL sends a message to the server at example.com.

  2. The server says, "Oh, you want the main page? Here is the HTML code for it."

  3. cURL prints that raw HTML code directly onto your terminal screen.

You won't see a pretty webpage, just the text that makes up the webpage. This is exactly what we want! It proves you can talk to the server.

4. Understanding Request and Response (The Conversation Structure)

Every conversation with a server has two parts: the Request (what you ask for) and the Response (what you get back).

The Request (Your Order)

When you use cURL, you are sending a structured "order" to the server. For now, we only need to know about two types of orders:

  1. **GET**: You are asking the server to **GET** you some information. (e.g., "Give me the list of products.")

  2. **POST**: You are asking the server to **POST** or create new information. (e.g., "Here is a new user account to save.")

The Response (The Delivery)

The server's answer is also structured. The most important part is the Status Code. Think of the Status Code like the server’s immediate reaction:

Status CodeReal-Life MeaningServer's Mood
200 OK"Got it! Here is what you asked for."Happy
404 Not Found"I looked everywhere, but that page doesn't exist."Confused
400 Bad Request"Your request was messed up. I can't even understand it."Annoyed
500 Internal Server Error"Something broke on my end. Not your fault, but I can't help."Stressed

To see the status code and other important details (called headers), you can add the -i flag (for "include headers") to your command:

Bash

curl -i https://google.com

The first line of the output will look something like this: HTTP/1.1 200 OK. That "200 OK" is your confirmation of success!

5. Using cURL to Talk to APIs

This is where cURL becomes a programmer's superpower.

An API (Application Programming Interface) is just a specific set of rules a server uses to let other programs talk to it. It’s like a waiter who only takes orders written on a specific notepad.

Let’s use a fake API to see GET and POST in action.

Example 1: GET (Asking for Information)

We want to get a todo from a todo-list from a fake API. This is a GET request.

curl

https://jsonplaceholder.typicode.com/todos/1

The server will send back a list of users, usually in a format called JSON (which is just a neat, organized way to write data ).

Example 2: POST (Sending New Information)

Now, we want to create a new user. This is a POST request, because we are sending data to the server to be saved.

We need to tell cURL three things:

  1. -X POST: We are using the POST method.

  2. -H "Content-Type: application/json": We are telling the server, "Hey, the data I'm sending is in JSON format." (This is a Header).

  3. -d '...': This is the actual Data (the new user's information).

Below is a curl command using the POST method.

If you get a 201 Created status code back, you did it! You just created a new piece of data on a server using nothing but your terminal.

6. Common Mistakes Beginners Make with cURL

Don't worry about making mistakes; that's how you learn! Here are the most common beginner traps:

MistakeThe ProblemThe Fix
Forgetting the MethodYou try to send data (POST ) but forget to add -X POST. cURL defaults to GET, so the server gets confused.Always use -X POST (or -X GET, -X PUT, etc.) when you are doing anything other than a simple GET.
Missing the HeaderYou send JSON data but forget the -H "Content-Type: application/json" header. The server doesn't know how to read your data.If you send data with -d, you almost always need to include the Content-Type header.
Using the Wrong QuotesYou use single quotes (') inside your JSON data, which breaks the command line's outer single quotes.Use double quotes (") inside your JSON data, and single quotes (') around the entire data block (-d '...').
Not Using -v for DebuggingYour request fails, and you have no idea why.Add the -v (verbose) flag to your command. It shows you the entire conversation (the headers, the connection details) so you can see exactly what went wrong.

Final Thoughts

cURL is your secret weapon for understanding the raw mechanics of the internet. It strips away the browser's fancy packaging and lets you see the pure conversation between your computer and the server.

Start simple: use curl https://anywebsite.com to see the raw HTML. Then, try curl -i https://anywebsite.com to see the status code.

Once you master these basics, you’ll find yourself reaching for cURL every time you need to quickly test an API, check a server’s status, or just peek behind the curtain of the web.

Happy coding! You’ve just leveled up your internet communication skills.