Skip to main content

Command Palette

Search for a command to run...

Getting Started with cURL

Updated
5 min read
Getting Started with cURL

A Beginner's Friendly Guide

When I first heard about cURL, I thought it was some fancy developer tool that would take me weeks to understand. Turns out, I was wrong. It's actually one of the simplest and most useful tools I've picked up in my web development journey. If you're just starting out, this guide is for you.

First Things First: What Even is a Server?

Before we jump into cURL, let's quickly understand why it exists.

Whenever you open a website, your browser is actually sending a message to a computer somewhere in the world called a server. This server holds all the website data and sends it back to you. Think of it like ordering food at a restaurant — you (the client) ask the waiter (your request), and the kitchen (server) prepares and sends back your meal (response).

You (Browser) → Request → Server → Response → You see the website

This back-and-forth happens every single time you load a webpage, submit a form, or scroll through your social media feed.

So What is cURL?

cURL (short for "Client URL") is a command-line tool that lets you send requests to servers directly from your terminal. No browser needed.

That's it. Seriously.

Instead of opening Chrome and typing a URL, you can just open your terminal and type a cURL command. The server doesn't care whether the request comes from a browser or from cURL — it just responds.

Here's a simple way to visualize it:

┌─────────────┐                    ┌─────────────┐
│   Browser   │ ──── Request ────► │   Server    │
└─────────────┘ ◄─── Response ──── └─────────────┘

        vs.

┌─────────────┐                    ┌─────────────┐
│    cURL     │ ──── Request ────► │   Server    │
│ (Terminal)  │ ◄─── Response ──── └─────────────┘
└─────────────┘

Both do the same thing. cURL just gives you more control and doesn't render pretty HTML.

Why Should You Even Care About cURL?

Good question. Here's why I started using it:

  1. Testing APIs without writing code — When you're building a backend, you want to quickly test if your endpoints work. cURL lets you do that in seconds.

  2. Debugging — Sometimes things break. cURL helps you see exactly what's being sent and received, with no browser magic hiding stuff from you.

  3. Automation — You can put cURL commands in scripts and automate repetitive tasks.

  4. It's everywhere — cURL comes pre-installed on most systems (Mac, Linux, even Windows now). You'll see it in documentation, tutorials, and Stack Overflow answers constantly.

Making Your First cURL Request

Okay, enough theory. Let's actually do something.

Open your terminal and type:

curl https://example.com

Hit enter. You should see a bunch of HTML printed on your screen. That's the webpage! You just fetched it without opening a browser.

Pretty cool, right?

Understanding the Request and Response

When you run that command, here's what actually happens:

Your Request:

  • You're sending a GET request (the default)

  • To the URL https://example.com

  • Asking the server: "Hey, give me whatever you have at this address"

The Response:

  • The server sends back HTML content

  • Along with a status code (like 200 for success)

  • And some headers (metadata about the response)

To see the status code and headers, add the -i flag:

curl -i https://example.com

Now you'll see something like:

HTTP/2 200
content-type: text/html; charset=UTF-8
...

<!doctype html>
<html>
...

That 200 means everything went fine. You might also see 404 (not found) or 500 (server error) — these status codes are super important for debugging.

Using cURL to Talk to APIs

This is where cURL really shines. APIs are basically servers that return data (usually JSON) instead of HTML.

Let's try fetching some fake user data:

curl https://jsonplaceholder.typicode.com/users/1

You'll get back something like:

{
  "id": 1,
  "name": "Leanne Graham",
  "username": "Bret",
  "email": "Sincere@april.biz"
  ...
}

That's actual data you can use in your applications!

GET vs POST

There are different types of requests. The two most common ones:

  • GET — Fetching data (what we've been doing)

  • POST — Sending data to create something new

Here's a simple POST example:

curl -X POST https://jsonplaceholder.typicode.com/posts \
  -H "Content-Type: application/json" \
  -d '{"title": "My Post", "body": "Hello World", "userId": 1}'

Breaking it down:

  • -X POST tells cURL we're sending a POST request

  • -H adds a header (telling the server we're sending JSON)

  • -d is the data we're sending

The server will respond confirming our "post" was created.

Where cURL Fits in Backend Development

Here's a simple diagram of where cURL helps:

┌─────────────────────────────────────────────────────────┐
│                  Your Development Flow                  │
├─────────────────────────────────────────────────────────┤
│                                                         │
│   Write Code → Test with cURL → Debug → Fix → Repeat   │
│                      ▲                                  │
│                      │                                  │
│            Quick feedback loop!                         │
│                                                         │
└─────────────────────────────────────────────────────────┘

Instead of building a whole frontend just to test if your API works, you fire off a cURL command and instantly know.

Common Mistakes Beginners Make (Including Me)

Let me save you some frustration:

1. Forgetting the protocol

# Wrong
curl example.com

# Right
curl https://example.com

Always include http:// or https://.

2. Not escaping special characters

If your data has spaces or special characters, wrap it in quotes properly.

3. Missing Content-Type header for POST requests

When sending JSON, always tell the server:

-H "Content-Type: application/json"

4. Copy-pasting commands without understanding them

We've all done it. But take a moment to understand what each flag does. It'll save you hours of debugging later.

5. Ignoring the response status code

Just because you got a response doesn't mean it worked. Always check if it's a 200, 201, or something else.

Wrapping Up

cURL might seem intimidating at first, but it's really just a way to send messages to servers without a browser. Start simple — fetch a webpage, then try an API, then experiment with POST requests.

The more you use it, the more natural it becomes. And honestly, once you get comfortable with cURL, you'll wonder how you ever tested APIs without it.

Happy coding! 🚀


This article is part of my learning journey in the Web Dev Cohort 2026. If you found this helpful, feel free to connect!