Skip to main content

Command Palette

Search for a command to run...

Getting Started with cURL

Published
3 min read

What Is cURL?

At its core, cURL is a command‑line tool that lets you send messages to a server and see what the server sends back - all from your terminal or command prompt. It’s short for Client for URLs and supports many protocols like HTTP and HTTPS, so you can fetch webpages or talk to APIs without a browser.

Think of cURL as a way to ask a server:

“Hey server - send me this resource!”

and the server replies with data.

Why Programmers Need cURL

cURL is useful because:

  • It lets you test HTTP requests without a browser.

  • It shows raw server responses, so you understand exactly what’s going on.

  • It’s great for talking to APIs - tools that return JSON data.

  • You can automate requests in scripts or cron jobs.

In short: it’s powerful for both learning and real backend development.

Your First cURL Request

Let’s start with the simplest command possible:

curl https://example.com

This sends a GET request to the server at example.com. By default, cURL uses the GET method, which means “fetch this resource.”

When you run this, your terminal will print HTML - the raw content of the webpage - just like your browser would get, but without rendering it.

What Just Happened?

  1. You sent a request - cURL asked the server for the homepage.

  2. Server responded - it sent back HTML text.

  3. You saw it on screen - cURL printed the response.

Your browser normally renders this HTML into a webpage, but cURL just shows the raw data for clarity.

Understanding Request and Response

Every interaction with a server has two parts:

Request (What You Send)

Includes:

  • URL: Where you’re sending the request

  • Method: What action you want (GET or POST)

  • Headers & Body: Extra info (optional)

Examples of common request methods:

  • GET - ask for data

  • POST - send data to the server

Response (What You Get Back)

A server reply contains:

  • Status Code - HTTP code telling you success or failure

  • Headers - metadata about the response

  • Body - the actual data (HTML, JSON, etc.)

To see wħat the server sends back (including headers), you can use:

curl -v https://example.com

This shows you both request and response details.

Using cURL to Talk to APIs

APIs (Application Programming Interfaces) are servers that return structured data, usually JSON, when you call them.

Example - fetching GitHub API data:

curl https://api.github.com

This prints JSON text right in your terminal.

Here’s the idea:

cURL → API server → JSON response → printed in terminal

GET vs POST

  • GET - Used to retrieve data.

curl https://example.com

Simple and safe.

  • POST - Used to send data (like form submission).

curl -X POST https://httpbin.org/post -d "name=John"

Adds data to be processed by the server.

Common Mistakes Beginners Make

Here are some mistakes many newcomers make:

  • Forgetting quotes around URLs with spaces

  • Wrong method or data format with POST
    Always use quotes and correct syntax.

  • Ignoring status codes
    Look at HTTP/2 200 for success.

cURL vs Browser: What’s the Difference?

Browser                    cURL
   ↓                          ↓
request via browser     request via terminal
   ↓                          ↓
renders HTML visually      prints raw text
   ↓                          ↓
user sees webpage         developer sees data

Your browser does extra work - rendering, JavaScript, styles - while cURL focuses on pure data. That makes it ideal for developers.

Final Summary

cURL is a simple yet powerful tool that lets you:

  • Make HTTP requests from your terminal

  • Fetch webpages or API data

  • See raw server responses

  • Practice real HTTP methods like GET and POST

All this makes it essential for backend development, debugging, and learning how servers work.