requests 0.1.6

http requests

To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:


Build Status

HTTP requests library with goals:

  • small memory footprint
  • performance
  • simple, high level API

API docs: Wiki

In simplest scenario you just need to fetch and process document from remote site. In this case you can call getContent

import std.stdio;
import std.algorithm;
import requests;

pragma(lib, "ssl");
pragma(lib, "crypto");

void main() {

getContent returns Buffer, filled with data. Buffer looks like Appender!ubyte (it have method data()), but also support many Range operations.

If you have to send some parameters with request, then you can use next simple inrerface:

    string name = "user";
    r = getContent("", "name", name, "age", 42);

The simple way to upload content is postContent() API call.

Posting to forms using x-form/x-www-form-urlencoded:

postContent("", queryParams("first", "a", "second", 2));

Using multipart/form-data (also upload files to forms, see examples in unitests for HTTPRequest):

MultipartForm form;
form.add(formData("greeting", cast(ubyte[])"hello"));
postContent("", form);

If you do not need upload to form, then you can post from range(see more examples in section HTTPRequest).

postContent("", `{"a":"b", "c":1}`, "application/json");

When you need access to response code, you have to use Request and Response structures:

Request rq = Request();
Response rs = rq.get("");

For anything other than default, you can configure Request structure for keep-alive, redirects, headers, or for different io-buffer and maximum sizes of response headers and body.

For example to authorize with Basic authorization use next code:

    rq = Request();
    rq.authenticator = new BasicAuthentication("user", "passwd");
    rs = rq.get("");

You can use requests in parallel tasks (but you can't share single Request structure between threads):

import std.stdio;
import std.parallelism;
import std.algorithm;
import std.string;
import core.atomic;

immutable auto urls = [

void main() {    

    shared short lines;
    foreach(url; parallel(urls)) {
        atomicOp!"+="(lines, getContent(url).splitter("\n").count);
    assert(lines == 287);

Here is short descrition of some Request options:

keepAliveboolrequest keepalive connectionfalse
maxRedirectsuintmaximum redirect depth10
maxHeadersLengthsize_tmax.acceptable response headers length32KB
maxContentLengthsize_tmax.acceptable content length5MB
timeoutDurationtimeout on connect or data transfer30.seconds
bufferSizesize_tsocket io buffer size16KB
verbosityuintverbosity level (0, 1 or 2)0
proxystringurl of the http proxynull
headersstring[string]additional headersnull

Usage example:

 auto rq = Request();
 auto rs = rq.get("");

 rq.keepAlive = true;
 rs ="", `{"a":"b", "c":[1,2,3]}`, "application/json");

 auto f = File("tests/test.txt", "rb");
 rs ="", f.byChunk(3), "application/octet-stream");
 auto data = parseJSON(["data"].str;

For Windows users

If building or testing under windows fails with message about ssl, then inslall libssl32.lib and ssleay32.lib into dmd or ldc2 library path. You can find this libs on These libararies were downloaded from (full version) and converted using "implib /system" If you know better way to link windows libraries, please, let me know.

  • ikod
2.0.9 2022-Oct-22
2.0.8 2022-May-15
2.0.7 2022-May-09
2.0.6 2022-Apr-27
2.0.5 2022-Apr-23
Show all 83 versions
Download Stats:
  • 67 downloads today

  • 590 downloads this week

  • 6963 downloads this month

  • 217239 downloads total

Short URL: