Buffer!ubyte which you can use as ForwardRange or DirectAccessRange, or extract data with .data() method.
import std.algorithm; import std.stdio; import std.json; globalLogLevel(LogLevel.info); info("Test getContent"); auto r = getContent("https://httpbin.org/stream/20"); assert(r.splitter('\n').filter!("a.length>0").count == 20); r = getContent("ftp://speedtest.tele2.net/1KB.zip"); assert(r.length == 1024); r = getContent("https://httpbin.org/get", ["a":"b", "c":"d"]); string name = "user", sex = "male"; int age = 42; r = getContent("https://httpbin.org/get", "name", name, "age", age, "sex", sex); info("Test receiveAsRange with GET"); auto rq = Request(); rq.useStreaming = true; rq.bufferSize = 16; auto rs = rq.get("http://httpbin.org/get"); auto stream = rs.receiveAsRange(); ubyte[] streamedContent; while( !stream.empty() ) { streamedContent ~= stream.front; stream.popFront(); } rq = Request(); rs = rq.get("http://httpbin.org/get"); assert(streamedContent == rs.responseBody.data); rq.useStreaming = true; streamedContent.length = 0; rs = rq.get("ftp://speedtest.tele2.net/1KB.zip"); stream = rs.receiveAsRange; while( !stream.empty() ) { streamedContent ~= stream.front; stream.popFront(); }
globalLogLevel(LogLevel.info); info("Test get in parallel"); import std.stdio; import std.parallelism; import std.algorithm; import std.string; import core.atomic; immutable auto urls = [ "http://httpbin.org/stream/10", "https://httpbin.org/stream/20", "http://httpbin.org/stream/30", "https://httpbin.org/stream/40", "http://httpbin.org/stream/50", "https://httpbin.org/stream/60", "http://httpbin.org/stream/70", ]; defaultPoolThreads(3); shared short lines; foreach(url; parallel(urls)) { atomicOp!"+="(lines, getContent(url).splitter("\n").count); } assert(lines == 287);
Call GET, and return response content. args = variadic args to supply parameter names and values.