Skip to main content

Command Palette

Search for a command to run...

Getting Started with cURL

Published
3 min readView as Markdown
Getting Started with cURL

What Is cURL? (Very Simple Explanation)

cURL is a command-line tool that lets you send requests to a server and see the response.

In simple words:

cURL helps your computer talk to another computer over the internet.

When you use a browser:

  • You type a URL

  • The browser sends a request

  • The server sends a response (HTML, JSON, etc.)

cURL does the same thing, but without a browser.

https://53.fs1.hubspotusercontent-na1.net/hubfs/53/curl-command-1-20240924-8716216.webp

https://www.researchgate.net/publication/228662293/figure/fig1/AS%3A654412636749824%401533035539067/client-server-Request-and-Response.png


Why Programmers Need cURL

Browsers hide many details.

Programmers need to:

  • Test APIs

  • Debug backend responses

  • Send requests without a UI

  • Automate HTTP calls

  • Check headers and status codes

cURL is useful because:

  • It works everywhere

  • It is fast

  • It shows raw request and response

  • It does exactly what you ask (no hidden behavior)


Making Your First Request Using cURL

Let’s start with the simplest request.

curl https://example.com

What happens here:

  • cURL sends a GET request

  • Server responds with data

  • cURL prints the response in the terminal

This is similar to opening example.com in a browser, but you only see the response body.


Understanding Request and Response

Every internet communication follows this pattern:

Request → Server → Response

https://www.researchgate.net/publication/228703446/figure/fig1/AS%3A301961011318788%401449004523443/Flowchart-of-request-response-process.png

https://loopback.io/pages/en/lb4/imgs/req-res-high-level.png

Request contains:

  • URL

  • Method (GET, POST, etc.)

  • Headers

  • Optional body (data)

Response contains:

  • Status code (200, 404, 500)

  • Headers

  • Body (HTML, JSON, text)

cURL lets you see and control these parts.


Seeing Response Details (Status & Headers)

To see response headers:

curl -i https://example.com
  • -i means “include headers”

  • Useful for debugging API responses

You’ll see:

  • HTTP status

  • Content type

  • Server info


Using cURL to Talk to APIs

Most APIs return JSON, not HTML.

Example API request:

curl https://api.github.com

The response will look like JSON data.

This is how backend and frontend communicate internally.


Sending Data (POST Request)

curl -X POST https://example.com/api \
  -H "Content-Type: application/json" \
  -d '{"name":"Aman","age":20}'

Explanation:

  • -X POST → HTTP method

  • -H → header

  • -d → request body (data)

This is how:

  • Forms submit data

  • Login APIs work

  • Backend receives input

https://svitla.com/uploads/ckeditor/01_27.05.jpg

https://kajabi-storefronts-production.kajabi-cdn.com/kajabi-storefronts-production/file-uploads/blogs/2147485434/images/315487-7af3-d17-c8af-0b4d8af188db_rest-api-model-diagram.png


Common cURL Options (Beginner Useful)

OptionMeaning
-XHTTP method
-HAdd headers
-dSend data
-iShow headers
-vVerbose (debug mode)

You don’t need all of them at once.
Use only what your request needs.


Common Mistakes Beginners Make with cURL

1. Forgetting Quotes

-d {name:Aman}

-d '{"name":"Aman"}'

2. Wrong Content-Type

Sending JSON without header causes server errors.

Always add:

-H "Content-Type: application/json"

3. Using GET When API Expects POST

If API expects data:

  • GET won’t work

  • Use POST, PUT, or PATCH


4. Thinking cURL Is Only for Backend Devs

Frontend developers use cURL to:

  • Test APIs before UI

  • Debug CORS issues

  • Verify backend responses


How cURL Fits in Real Development

https://svitla.com/uploads/ckeditor/01_27.05.jpg

https://www.slideteam.net/media/catalog/product/cache/1280x720/f/r/framework_flowchart_of_api_test_automation_slide01.jpg

Typical flow:

  • Backend builds API

  • cURL tests API

  • Frontend connects UI

  • Bugs fixed faster

cURL acts as a bridge between frontend and backend.

More from this blog

blog

14 posts

This contains Basics of Git, Networks and HTML