View source code
Display the source code in std/net/curl.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.


Networking client functionality as provided by libcurl. The libcurl library must be installed on the system in order to use this module.


You may need to link to the curl library, e.g. by adding "libs": ["curl"] to your dub.json file if you are using DUB.

Windows x86 note: A DMD compatible libcurl static library can be downloaded from the download archive page.

Compared to using libcurl directly this module allows simpler client code for common uses, requires no unsafe operations, and integrates better with the rest of the language. Futhermore it provides range access to protocols supported by libcurl both synchronously and asynchronously.

A high level and a low level API are available. The high level API is built entirely on top of the low level one.

The high level API is for commonly used functionality such as HTTP/FTP get. The byLineAsync and byChunkAsync provides asynchronous range that performs the request in another thread while handling a line/chunk in the current thread.

The low level API allows for streaming and other advanced features.

Cheat Sheet
Function Name Description
    High level
download download("", "/tmp/downloaded-ftp-file") downloads file from URL to file system.
upload upload("/tmp/downloaded-ftp-file", ""); uploads file from file system to URL.
get get("") returns a char[] containing the web page.
put put("", "Hi") returns a char[] containing the web page. after a HTTP PUT of "hi"
post post("", "Hi") returns a char[] containing the web page. after a HTTP POST of "hi"
byLine byLine("") returns a range of char[] containing the web page.
byChunk byChunk("", 10) returns a range of ubyte[10] containing the web page.
byLineAsync byLineAsync("") returns a range of char[] containing the web page asynchronously.
byChunkAsync byChunkAsync("", 10) returns a range of ubyte[10] containing the web page asynchronously.
    Low level
HTTP HTTP struct for advanced usage
FTP FTP struct for advanced usage
SMTP SMTP struct for advanced usage


import, std.stdio;

// Return a char[] containing the content specified by a URL
auto content = get("");

// Post data and return a char[] containing the content specified by a URL
auto content = post("", ["name1" : "value1", "name2" : "value2"]);

// Get content of file from ftp server
auto content = get("");

// Post and print out content line by line. The request is done in another thread.
foreach (line; byLineAsync("", "Post data"))

// Get using a line range and proxy settings
auto client = HTTP();
client.proxy = "";
foreach (line; byLine("", client))

For more control than the high level functions provide, use the low level API:


import, std.stdio;

// GET with custom data receivers
auto http = HTTP("");
http.onReceiveHeader =
    (in char[] key, in char[] value) { writeln(key, ": ", value); };
http.onReceive = (ubyte[] data) { /+ drop +/ return data.length; };

First, an instance of the reference-counted HTTP struct is created. Then the custom delegates are set. These will be called whenever the HTTP instance receives a header and a data buffer, respectively. In this simple example, the headers are written to stdout and the data is ignored. If the request should be stopped before it has finished then return something less than data.length from the onReceive callback. See onReceiveHeader/onReceive for more information. Finally the HTTP request is effected by calling perform(), which is synchronous.


The functionally is based on libcurl. LibCurl is licensed under an MIT/X derivative license.


byChunk(url, chunkSize, conn) HTTP/FTP fetch content as a range of chunks.
byChunkAsync(url, postData, chunkSize, transmitBuffers, conn) HTTP/FTP fetch content as a range of chunks asynchronously.
byLine(url, keepTerminator, terminator, conn) HTTP/FTP fetch content as a range of lines.
byLineAsync(url, postData, keepTerminator, terminator, transmitBuffers, conn) HTTP/FTP fetch content as a range of lines asynchronously.
connect(url, conn) HTTP connect request.
del(url, conn) HTTP/FTP delete content.
download(url, saveToPath, conn) HTTP/FTP download to local file system.
get(url, conn) HTTP/FTP get content.
options(url, conn) HTTP options request.
patch(url, patchData, conn) HTTP patch content.
post(url, postData, conn) HTTP post content.
put(url, putData, conn) HTTP/FTP put content.
trace(url, conn) HTTP trace request.
upload(loadFromPath, url, conn) Upload file from local files system using the HTTP or FTP protocol.


CurlException Exception thrown on errors in functions.
CurlTimeoutException Exception thrown on timeout errors in functions.
HTTPStatusException Exception thrown on HTTP request failures, e.g. 404 Not Found.


Curl Wrapper to provide a better interface to libcurl than using the plain C API. It is recommended to use the HTTP/FTP etc. structs instead unless raw access to libcurl is needed.
FTP FTP client functionality.
HTTP HTTP client functionality.
SMTP Basic SMTP protocol support.


CurlCode int Equal to CURLcode
ThrowOnError Flag!("throwOnError") Flag to specify whether or not an exception is thrown on error.


Jonas Drewsen. Some of the SMTP code contributed by Jimmy Cao.


Boost License 1.0.