Skip to main content

Command Palette

Search for a command to run...

Getting started with cURL

Published
•2 min read•View as Markdown
Getting started with cURL
B
I write funny shayaris and sad code.

What is cURL?

cURL (short for “Client URL”) is a command-line tool that lets you send requests to servers from your terminal and see their responses. It’s like using your terminal to “talk” to websites or APIs instead of a browser.

Why programmers need cURL

  • Quick connectivity checks: “Is this server/API reachable?”

  • Inspecting responses: See raw HTML, JSON, or error messages to debug.

  • Fast iteration: Test endpoints without writing code or opening a browser.

Making your first request using cURL

  • Reminder: A server is a computer on the internet that listens for requests and sends back responses (web pages, API data, files).

  • Simplest GET request (fetch a web page):

    • curl https://example.com

    • This sends a GET request and prints the response body (e.g., the HTML) in your terminal.

  • Tip: Start with just curl URL to build confidence. Add options later.

Understanding request and response

  • Request: Method (GET or POST), URL, optional headers/body.

  • Response parts:

    • Status code (200 OK, 404 Not Found, 500 Server Error, etc.).

    • Headers (metadata like Content-Type: application/json).

    • Body (the actual content: HTML, JSON, text, etc.).

  • By default, curl shows you the body. To see headers too, add -i (later, once you’re comfortable).

Using cURL to talk to APIs

  • GET (fetch data):

  • POST (send data):

  • For JSON APIs, a minimal example (when ready to add a header):

  • Start with simple GET; add POST and minimal headers when needed.

Common mistakes beginners make with cURL

  • Using the wrong URL (missing https:// or the wrong endpoint).

  • Forgetting data with POST (no -d) or forgetting to set the method (-X POST).

  • Expecting JSON but hitting an HTML page (wrong endpoint or URL).

  • Adding too many flags too soon; stick to curl URL first, then layer options gradually.

More from this blog

B

Bhupendra Web Dev Cohort 2026

24 posts

Hey !! I am a CS enthusiast currently on a Web Development journey through Hitesh Sir's Web Dev Cohort 2026. Let's see how this goes.