Skip to main content

Command Palette

Search for a command to run...

Exploring cURL

Published
2 min readView as Markdown
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.

Client-Server Architecture Explained

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:

  1. You can test APIs without building a frontend

  2. You can debug backend endpoints quickly

  3. You can understand how requests and responses actually work

  4. 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:

  1. The Request: You ask for something (e.g., curl google.com).A request usually contains

    Method (GET, POST, etc.),URL (where you are sending the request), Data or headers

  2. The Processing: The server looks up your request.

  3. 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

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 jq to make JSON look pretty!).

Browser vs cURL

Browser: UI → Request → Server → Response → UI

cURL: Terminal → Request → Server → Response → Terminal

More from this blog

Web Dev Cohort

13 posts