How do you test backend APIs directly without building a front end? How do you inspect what’s actually sent over the wire? curl provides a CLI interface to speak HTTP directly—essential for backend development and debugging.
curl is a command-line tool that sends HTTP requests and prints the response. It bypasses browsers—you can directly test endpoints, inspect headers, send POST data. It’s the backend developer’s direct connection to the server.
- Parse URL: curl extracts protocol, domain, port, path from the URL
- DNS Lookup: Resolves domain to IP address
- Socket Connection: Opens TCP socket to IP:port
- TLS Handshake: For HTTPS, establishes encrypted connection
- Send Request: Writes raw HTTP request text to socket
- Receive Response: Reads response from server and prints to terminal
Example: curl https://example.com sends GET / HTTP/1.1 and prints the HTML response.
- CLI tool available on all major operating systems
- Supports multiple protocols: HTTP, HTTPS, FTP, etc.
- Options: -X (method), -H (headers), -d (body), -v (verbose)
- Great for API testing:
curl -X POST -H "Content-Type: application/json" -d '{"name":"ani"}' https://api.example.com - -v flag shows full request/response headers and connection details
- Does not execute JavaScript like browsers do
- Built from: Socket — curl creates socket connections
- Built from: HTTP Protocol — curl sends HTTP requests
- Built from: TLS Handshake — curl handles HTTPS automatically
- Related: DNS — curl uses DNS to resolve domains
- Related: Backend as Program — curl talks to backend servers
- Doesn’t render HTML or execute JavaScript—just shows raw response
- Default timeout may be too long for failing servers
- Use -L to follow redirects
- For complex APIs, tools like Postman may be more convenient than curl