How to download a file over HTTP
Codemia Knowledge Hub ·
From a terminal, run curl -O http://example.com/file.zip or wget http://example.com/file.zip. In code, send an HTTP GET request and write the response body to a file, for example with Python's requests or Node.js axios.
Under the hood, your browser or tool sends a GET request to the server hosting the file. The server responds with the file content, plus metadata in the response headers such as the file type and size.
Command line: curl and wget
curl supports many protocols, including HTTP, HTTPS and FTP, and ships with most Unix-based systems (Linux, macOS).
-O saves the file under the same name as in the URL.
wget is designed for non-interactive downloads from the web, so it is a little simpler for basic file downloads:
Python with requests
requests is the most common Python library for HTTP:
This fetches the file and writes it to disk.
Node.js with axios
responseType: 'stream' lets you pipe the response straight into a file.
Comparing the options
| Tool or Language | Command/Code | Pros | Cons |
| curl | curl -O http://example.com/file.zip | Highly configurable, versatile | Steeper learning curve |
| wget | wget http://example.com/file.zip | Simpler for direct downloads | Less flexible than curl |
| Python | requests.get(url) | Simple syntax, powerful | Requires external lib |
| Node.js | axios({method: 'get', url: url, responseType: 'stream'}) | Asynchronous support, modern | Slightly verbose |
Practical checks
- File size: before a large download, check the
Content-Lengthheader if available to make sure there is enough storage. - HTTPS: prefer HTTPS over HTTP for integrity and privacy.
- Errors: handle timeouts, network failures and corrupt downloads.
- Rate limits: when downloading from an API, respect its rate limits and usage guidelines.
Related reading
- How to easily do an async REST request in Perl?
- how to enable api flags in kubernetes
- How to enable Bearer authentication on Spring Boot application?
- How to enable Client Certificate Authentication with Traefik Kubernetes?
- How to enable CORS in flask
- How to enable HTTP response caching in Spring Boot
- How to enable POST, PUT AND DELETE methods in spring security
- How To Estimate the total time to complete the request In UDP and TCP ( Distributed Systems)
System design interview problems on this topic
- Design a Load Balancer: solution and walkthrough
- Design a Domain Name System: solution and walkthrough
- Design a Global Content Distribution Network: solution and walkthrough
- Design an API Rate Limiter: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.