β‘ The Universal Swiss Army Knife for API Engineering
cURL (Client URL) is the foundational command-line interface and network transfer engine powering automated testing, continuous integration checks, and server diagnostic tasks across every enterprise computing platform. Unlike heavy graphical clients, cURL operates directly inside terminal environments, Docker containers, and CI/CD pipelines with zero graphical overhead. When paired with streamlined command-line parsers like jq and httpie, cURL enables test engineers to execute low-level protocol debugging, extract exact cryptographic handshakes, inspect headers, benchmark sub-millisecond network timings, and compose headless regression tests that execute deterministically anywhere.
CURL CORE COMMAND STRUCTURE:
curl [OPTIONS] <URL>
PRIMARY FLAG REFERENCE MATRIX:
ββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β FLAG SHORT β LONG FORM β PURPOSE & ARCHITECTURAL BEHAVIOR β
ββββββββββββββββββββββΌβββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β -X <METHOD> β --request <METHOD> β Specifies HTTP verb: GET, POST, PUT, PATCH, DELETE, OPTIONS β
β -H <HEADER> β --header <HEADER> β Injects custom HTTP headers (e.g., 'Content-Type: app/json') β
β -d <DATA> β --data / --data-raw β Transmits HTTP POST body data (automatically sets POST verb) β
β --data-binary β --data-binary @file β Sends binary payload without stripping newlines or whitespace β
β -i β --include β Displays HTTP response status line and headers alongside body β
β -I β --head β Performs HEAD request; displays response headers only β
β -s β --silent β Mutes progress meter and diagnostic logs β
β -S β --show-error β Used with -s to emit error strings only if the command fails β
β -v β --verbose β Outputs complete TCP/TLS handshake and wire protocol trace β
β -L β --location β Automatically follows HTTP 3xx redirection headers to target β
β -k β --insecure β Bypasses SSL/TLS certificate verification (staging only!) β
β -o <FILE> β --output <FILE> β Writes server response body to local disk file instead of stdoutβ
β -u <USR:PWD> β --user <USER:PASSWORD> β Encodes credentials into standard Basic Authentication header β
β -F <NAME=@> β --form <NAME=@FILE> β Emits multipart/form-data for file uploads and form inputs β
ββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# 1. READ RESOURCE (GET)
curl -s -X GET "https://api.nikita-infotech.com/api/v1/students/STU-99214" \
-H "Accept: application/json" \
-H "Authorization: Bearer eyJhbGciOiJIUzI1Ni..."
# 2. CREATE RESOURCE (POST) with JSON Payload
curl -s -i -X POST "https://api.nikita-infotech.com/api/v1/students" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer eyJhbGciOiJIUzI1Ni..." \
-d '{
"name": "Nikita Sharma",
"courseCode": "API-AUTOMATION-PRO",
"batch": "WEEKEND"
}'
# 3. FULL REPLACEMENT (PUT)
curl -s -i -X PUT "https://api.nikita-infotech.com/api/v1/students/STU-99214" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer eyJhbGciOiJIUzI1Ni..." \
-d '{
"name": "Nikita Sharma",
"courseCode": "API-AUTOMATION-PRO",
"batch": "WEEKDAY",
"status": "ACTIVE"
}'
# 4. PARTIAL UPDATE (PATCH)
curl -s -i -X PATCH "https://api.nikita-infotech.com/api/v1/students/STU-99214" \
-H "Content-Type: application/merge-patch+json" \
-H "Authorization: Bearer eyJhbGciOiJIUzI1Ni..." \
-d '{"batch": "EVENING"}'
# 5. REMOVE RESOURCE (DELETE)
curl -s -i -X DELETE "https://api.nikita-infotech.com/api/v1/students/STU-99214" \
-H "Authorization: Bearer eyJhbGciOiJIUzI1Ni..."
-v) reveals the complete networking pipeline: IP resolution, TCP 3-way handshake, TLS 1.3 cryptographic cipher negotiation, and raw HTTP stream markers.
# Run verbose handshake command against secure API
curl -v -X GET "https://api.nikita-infotech.com/api/v1/health"
# 1. BEARER TOKEN / JSON WEB TOKEN (JWT)
curl -s -X GET "https://api.nikita-infotech.com/api/v1/account" \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI..."
# 2. HTTP BASIC AUTHENTICATION via -u flag (Automatically generates Base64 header)
curl -s -u "api_admin:SecurePass#2026" \
"https://api.nikita-infotech.com/api/v1/admin/metrics"
# Equivalent manual Base64 header injection for Basic Auth:
# echo -n "api_admin:SecurePass#2026" | base64 -> YXBpX2FkbWluOlNlY3VyZVBhc3MjMjAyNg==
curl -s -H "Authorization: Basic YXBpX2FkbWluOlNlY3VyZVBhc3MjMjAyNg==" \
"https://api.nikita-infotech.com/api/v1/admin/metrics"
# 3. CUSTOM API KEY IN HEADERS
curl -s -X GET "https://api.nikita-infotech.com/api/v1/telemetry" \
-H "X-API-KEY: key_live_99214810294" \
-H "X-Client-App-ID: NikitaAutomationRunner"
# 4. API KEY VIA QUERY PARAMETER
curl -s -X GET "https://api.nikita-infotech.com/api/v1/weather?apiKey=key_live_99214810294&city=Pune"
jq (command-line JSON processor) formats payloads, extracts specific keys, filters arrays, and validates nested fields instantly.
# 1. Pretty-print raw JSON response
curl -s "https://jsonplaceholder.typicode.com/users/1" | jq .
# 2. Extract specific scalar fields (Name and Email)
curl -s "https://jsonplaceholder.typicode.com/users/1" | jq '{name: .name, email: .email}'
# 3. Extract array length
curl -s "https://jsonplaceholder.typicode.com/posts" | jq 'length'
# 4. Filter array objects matching condition (e.g., posts where userId == 1)
curl -s "https://jsonplaceholder.typicode.com/posts" | jq '[.[] | select(.userId == 1)] | length'
# 5. Extract only titles from filtered array as clean plaintext (raw output: -r)
curl -s "https://jsonplaceholder.typicode.com/posts" | jq -r '.[:3] | .[].title'
# 6. Extract token from login call and assign directly to Shell Variable
TOKEN=$(curl -s -X POST "https://api.nikita-infotech.com/api/v1/auth/login" \
-H "Content-Type: application/json" \
-d '{"user":"admin","pass":"secret"}' | jq -r .access_token)
echo "Extracted Token: ${TOKEN:0:15}..."
multipart/form-data encoding. The -F flag formats boundaries, filenames, and MIME types automatically.
# 1. Standard single-file upload
curl -s -i -X POST "https://api.nikita-infotech.com/api/v1/resumes/upload" \
-H "Authorization: Bearer $AUTH_TOKEN" \
-F "resume=@/home/user/documents/Nikita_Resume.pdf"
# 2. File upload with explicit MIME type override and accompanying text metadata
curl -s -i -X POST "https://api.nikita-infotech.com/api/v1/profile/avatar" \
-H "Authorization: Bearer $AUTH_TOKEN" \
-F "avatar=@profile_pic.png;type=image/png" \
-F "studentId=STU-99214" \
-F "cropSettings={\"x\":0,\"y\":0,\"width\":200,\"height\":200};type=application/json"
# 3. Stream binary file directly via --data-binary (for raw octet-stream endpoints)
curl -s -i -X PUT "https://api.nikita-infotech.com/storage/backups/db_dump.sql.gz" \
-H "Content-Type: application/gzip" \
-H "Authorization: Bearer $AUTH_TOKEN" \
--data-binary "@/tmp/db_dump.sql.gz"
--write-out (-w) parameter allows you to capture exact performance benchmarks across DNS resolution, TCP handshake, TLS negotiation, TTFB, and transfer speeds.
# Create custom format specification: curl_timing_format.txt
# -------------------------------------------------------------
# \n --- API PERFORMANCE BENCHMARK REPORT ---
# HTTP Status Code : %{http_code}\n
# DNS Resolution Time : %{time_namelookup} s\n
# TCP Handshake Time : %{time_connect} s\n
# SSL/TLS Handshake Time : %{time_appconnect} s\n
# Pre-Transfer Time : %{time_pretransfer} s\n
# Time to First Byte : %{time_starttransfer} s\n
# Total Transaction Time : %{time_total} s\n
# Download Size : %{size_download} bytes\n
# Speed Download : %{speed_download} bytes/s\n
# -------------------------------------------------------------
# Execute benchmarking command:
curl -s -o /dev/null -w "@curl_timing_format.txt" "https://api.nikita-infotech.com/api/v1/students"
-c) and cookie-read (-b) parameters.
# Step 1: Authenticate and write issued Set-Cookie directives to local jar file
curl -s -c cookies.txt -X POST "https://api.nikita-infotech.com/login" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "username=student_user&password=TestPassword123"
# Step 2: Inspect generated Netscape-format cookie jar
cat cookies.txt
# Step 3: Reuse authenticated cookie jar for subsequent protected API calls
curl -s -b cookies.txt -X GET "https://api.nikita-infotech.com/api/v1/dashboard"
# Step 4: Inject inline one-time cookie without file storage
curl -s -b "SESSION_ID=abc123xyz; TRACKING_OPT_OUT=true" \
"https://api.nikita-infotech.com/api/v1/catalog"
#!/usr/bin/env bash
set -eo pipefail
BASE_URL="https://jsonplaceholder.typicode.com"
FAILED_TESTS=0
echo "=========================================================="
echo "π EXECUTING CURL AUTOMATED API REGRESSION SMOKE SUITE"
echo "=========================================================="
# Test Case 1: Validate Status Code and Field Value on GET /posts/1
echo -n "[TEST 1] GET /posts/1 -> Status 200 & userId == 1 ... "
RESPONSE=$(curl -s -w "\n%{http_code}" "${BASE_URL}/posts/1")
HTTP_STATUS=$(echo "$RESPONSE" | tail -n1)
BODY=$(echo "$RESPONSE" | sed '$d')
USER_ID=$(echo "$BODY" | jq -r '.userId')
if [[ "$HTTP_STATUS" -eq 200 ]] && [[ "$USER_ID" -eq 1 ]]; then
echo "β PASSED"
else
echo "β FAILED (Status: $HTTP_STATUS, userId: $USER_ID)"
FAILED_TESTS=$((FAILED_TESTS + 1))
fi
# Test Case 2: Validate Resource Creation on POST /posts
echo -n "[TEST 2] POST /posts -> Status 201 & ID Returned ... "
RESPONSE=$(curl -s -w "\n%{http_code}" -X POST "${BASE_URL}/posts" \
-H "Content-Type: application/json" \
-d '{"title":"API Masterclass","body":"cURL Testing","userId":101}')
HTTP_STATUS=$(echo "$RESPONSE" | tail -n1)
BODY=$(echo "$RESPONSE" | sed '$d')
RECORD_ID=$(echo "$BODY" | jq -r '.id')
if [[ "$HTTP_STATUS" -eq 201 ]] && [[ -n "$RECORD_ID" ]]; then
echo "β PASSED (Created ID: $RECORD_ID)"
else
echo "β FAILED (Status: $HTTP_STATUS)"
FAILED_TESTS=$((FAILED_TESTS + 1))
fi
# Test Case 3: Validate 404 on Nonexistent Resource
echo -n "[TEST 3] GET /posts/999999 -> Status 404 ... "
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "${BASE_URL}/posts/999999")
if [[ "$HTTP_STATUS" -eq 404 ]]; then
echo "β PASSED"
else
echo "β FAILED (Status: $HTTP_STATUS)"
FAILED_TESTS=$((FAILED_TESTS + 1))
fi
echo "=========================================================="
if [[ "$FAILED_TESTS" -eq 0 ]]; then
echo "π ALL TESTS PASSED SUCCESSFULLY"
exit 0
else
echo "β SMOKE SUITE FAILED WITH $FAILED_TESTS ERRORS"
exit 1
fi
COMMAND LINE API CLIENT COMPARISON MATRIX:
ββββββββββββββββββββ¬ββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββ
β TOOL β SYNTAX STYLE β PRIMARY STRENGTH β IDEAL USAGE SCENARIO β
ββββββββββββββββββββΌββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββ€
β cURL β curl -X POST -H '...' -d '' β Universal, installed on 100%β CI/CD pipelines, Docker β
β β β of servers, supports all OS β containers, shell tests β
β HTTPie β http POST :8000/api name=valβ Human-friendly syntax, auto β Interactive manual API β
β β β colored JSON, simple flags β exploration in terminal β
β Wget β wget --post-data="..." β Recursive file downloading, β File asset downloads, β
β β β mirror crawler capabilities β web archiving mirrors β
β grpcurl β grpcurl -plaintext ... list β Native Protocol Buffers, gRPCβ gRPC microservice β
β β β reflection & streaming RPCs β contract verification β
ββββββββββββββββββββ΄ββββββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββ€
β TOP 5 CURL RULES FOR API QA ENGINEERS: β
β 1. Always quote URLs: curl "https://api.domain.com/search?q=test&limit=10" (prevents & bash fork). β
β 2. Use -sS together: Keeps output quiet while still logging critical connection failure strings. β
β 3. Pipe to jq . for readability: Prevents massive single-line JSON blob clutter in your terminal. β
β 4. Extract benchmarks with -w: Isolate server backend latency without external measurement tools. β
β 5. Validate status codes in scripts: curl -s -o /dev/null -w "%{http_code}" extracts status cleanly. β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ