0
0
Linux CLIscripting~10 mins

curl for HTTP requests in Linux CLI - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - curl for HTTP requests
Start curl command
Parse URL and options
Open network connection
Send HTTP request
Receive HTTP response
Display or save response
End
curl starts by reading your command, connects to the web address, sends the request, gets the response, and shows it to you.
Execution Sample
Linux CLI
curl https://example.com
curl -I https://example.com
curl -X POST https://example.com
These commands fetch a webpage, get headers only, and send a POST request respectively.
Execution Table
StepCommand PartActionResult/Output
1curl https://example.comParse URL and default GET methodReady to connect to example.com
2Open network connectionConnect to example.com on port 443Connection established
3Send HTTP GET requestSend GET / HTTP/1.1Request sent
4Receive HTTP responseGet status and content200 OK and HTML content received
5Display responseShow HTML content in terminal<!doctype html>...
6curl -I https://example.comParse URL and HEAD methodReady to connect to example.com
7Open network connectionConnect to example.com on port 443Connection established
8Send HTTP HEAD requestSend HEAD / HTTP/1.1Request sent
9Receive HTTP headersGet status and headers only200 OK and headers received
10Display headersShow headers in terminalHTTP/1.1 200 OK Content-Type: text/html...
11curl -X POST https://example.comParse URL and POST methodReady to connect to example.com
12Open network connectionConnect to example.com on port 443Connection established
13Send HTTP POST requestSend POST / HTTP/1.1Request sent
14Receive HTTP responseGet status and content200 OK or other response
15Display responseShow response content in terminal<response content>
16EndNo more commandscurl exits
💡 curl finishes after receiving and displaying the response or headers.
Variable Tracker
VariableStartAfter 1After 2After 3Final
URLNonehttps://example.comhttps://example.comhttps://example.comhttps://example.com
MethodGET (default)GETHEAD (with -I)POST (with -X POST)POST
ConnectionClosedOpenOpenOpenClosed
ResponseNoneHTML contentHeaders onlyResponse contentDisplayed
Key Moments - 3 Insights
Why does curl show HTML content for the first command but only headers for the second?
Because the first command uses the default GET method which fetches the full page (see execution_table rows 1-5), while the second uses -I which sends a HEAD request to get only headers (rows 6-10).
What does the -X option do in curl?
It changes the HTTP method curl uses to send the request, like POST instead of GET (see execution_table rows 11-15).
Why does curl need to open a network connection each time?
Because it must connect to the server to send the request and receive the response (see connection state in variable_tracker and steps 2,7,12).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what HTTP method does curl use by default when no option changes it?
APOST
BGET
CHEAD
DPUT
💡 Hint
Check the 'Method' variable in variable_tracker and steps 1-5 in execution_table.
At which step does curl send the HTTP HEAD request?
AStep 13
BStep 3
CStep 8
DStep 4
💡 Hint
Look at execution_table rows for the command with -I option.
If you add -X PUT to the curl command, what changes in the execution_table?
AThe HTTP method changes to PUT in the 'Command Part' and 'Action' columns.
BThe URL changes to a different website.
CThe connection step is skipped.
Dcurl will not send any request.
💡 Hint
Refer to how -X POST changed the method in steps 11-15.
Concept Snapshot
curl sends HTTP requests from the command line.
Default method is GET.
Use -I for HEAD requests (headers only).
Use -X to specify other methods like POST.
curl connects, sends request, receives response, then shows it.
Full Transcript
curl is a command line tool to send HTTP requests. When you run curl with a URL, it connects to that address and sends a GET request by default. It then waits for the server to respond and shows you the response content. If you add -I, curl sends a HEAD request instead, which only fetches headers, not the full page. Using -X lets you change the HTTP method, for example to POST. Each time, curl opens a network connection, sends the request, gets the response, and displays it. This process ends when the response is fully received and shown.