Exploring cURL

Before we talk about cURL we need to understand Server.
What is a server?
A server is just a computer somewhere on the internet that stores data,runs applications and responds when someone asks it for something.

What is cURL?
cURL is a command-line tool that lets you send requests to servers from the terminal.cURL is a way to send messages to a server from your terminal and see the response.It does not require any UI or browser its just you and the server.
Why Programmers Need cURL?
As a programmer, cURL is extremely useful because:
You can test APIs without building a frontend
You can debug backend endpoints quickly
You can understand how requests and responses actually work
It works everywhere: Linux, macOS, Windows
Making Your First Request Using cURL
In your terminal type “curl https://www.google.com”

what is this output??You just sent a "GET" request to Google. You’ll see a wall of HTML code fly past. That is the server saying, "Here is the code for my homepage!"
Understanding Request and Response
Every time you use cURL, a three-step process occurs:
The Request: You ask for something (e.g.,
curlgoogle.com).A request usually containsMethod (GET, POST, etc.),URL (where you are sending the request), Data or headers
The Processing: The server looks up your request.
The Response: The server sends back a status code (like 200 OK) and the data.A response contains Status code (e.g., 200, 404, 500) and Data (HTML, JSON, text, etc.)
Using cURL to Talk to APIs
An APIs usually return JSON, not HTML. In your terminal type “curl https://jsonplaceholder.typicode.com/posts/1”

Introducing GET and POST
GET (Fetching Data): Asking the server to give you something.
- Example:
curlhttps://api.example.com/users
- Example:
POST (Sending Data): Giving the server something new to save.
- Example:
curl -X POST -d "name=John"https://api.example.com/users
- Example:
Common mistakes beginners make with cURL
Sometimes cURL doesn't show an error message if a page fails. Use
-v(verbose) to see the "behind the scenes" chatter.Missing Quotes: If your URL has special characters (like
&), always wrap it in quotes:"https://api.com?id=1&type=user".Formatting: Beginners often get overwhelmed by the wall of text. (Pro tip: Pipe your output to a tool like
jqto make JSON look pretty!).
Browser vs cURL
Browser: UI → Request → Server → Response → UI
cURL: Terminal → Request → Server → Response → Terminal




