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

1. What is cURL

Problem

When we open a website in a browser, we only see the final output.
But we do not understand how the request is sent in the background, which headers are going, and how the response is coming.
And it is also not clear how to talk to a server without using a browser.

Explanation

cURL is a command-line tool that is used to send requests to a server and receive responses.
In simple words, cURL is like a messenger that talks directly to the server on your behalf.

Example

You type in the terminal:
curl google.com

And you get the raw response from the server.

Summary

cURL is a tool that sends requests and gets responses.

2. Why programmers need cURL

Problem

Developers need to test whether the server is working properly or not, even without using a browser.

Explanation

Programmers use cURL to:

  • test APIs

  • debug servers

  • check headers and status codes

Example

Before building the frontend, if you want to check the backend, you can test it directly using cURL.

Summary

cURL is a developer’s testing tool.

3. Making your first request using cURL

Step 1: Check if cURL is installed

Type in terminal / CMD:
curl --version

If the version is shown → you are ready.

Step 2: Basic GET request

Example:
curl https://www.google.com

This will return Google’s HTML response.

Step 3: Calling an API (real use)

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

Response:
{ "userId": 1, "id": 1, "title": "...", "body": "..." }

This means we fetched data from the server.

Step 4: POST request (sending data)

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

  • -X POST → method

  • -H → header

  • -d → data (body)

    Step 5: Request with authentication

    curl https://api.example.com/profile-H "Authorization: Bearer YOUR_TOKEN"

    5. Using cURL to talk to APIs

    Problem

    Testing APIs in a browser is a bit limited.

    Explanation

    Using cURL, we can directly call APIs:

    • GET requests

    • POST requests

    • send headers with data

Example

curl https://api.github.com/users/octocat

This returns JSON data.

Summary

cURL = API calling tool.


6. Common mistakes beginners make with cURL

Problem

Beginners get errors and do not understand where the mistake is.

Explanation

Common mistakes:

  • forgetting http/https

  • wrong URL

  • internet is off

  • wrong quotes or spaces

Example

curl google.com (may not always work)
curl https://google.com (correct)

Summary

Most errors happen because of small typing mistakes.