ddn.api.net.http.client

Module ddn.api.net.http.client

Defines a small, robust, and idiomatic HTTP client API that supports both synchronous and asynchronous usage.

Types 10

classHttpException : Exception

Base exception type for the HTTP client API.

Constructors
this(string msg, Throwable next = null, string file = __FILE__, size_t line = __LINE__)Constructs an HTTP exception.

Exception thrown when an HTTP operation times out.

Constructors
this(string msg, Throwable next = null, string file = __FILE__, size_t line = __LINE__)Constructs a timeout exception.

Standard HTTP methods.

GET
HEAD
POST
PUT
DELETE
OPTIONS
TRACE
CONNECT
PATCH

A case-insensitive header map.

Header names are normalized to lower case for lookups.

Fields
private string[string] _values
Methods
string opIndex(string name) constMap-like read access.
string opIndex(string name) refMap-like read/write access.
void opIndexAssign(string value, string name)Map-like assignment: `headers["name"] = "value"`.
void opIndexAssign(typeof(null), string name)Map-like delete: `headers["name"] = null`.
const(string) * opBinaryRight(string op : "in")(string name) constSupports `"name" in headers`.
int opApply(scope int delegate(const string name, const string value) dg) constForeach iteration support over stored headers.
void set(string name, string value)Sets (adds or replaces) a header.
bool has(string name) constReturns true if the header is present.
string get(string name, string defaultValue = "") constGets a header value.
void remove(string name)Removes a header if present.
size_t length() @property constReturns the number of stored headers.
const(string[string]) values() @property constReturns the underlying normalized header map.
HttpHeaders dup() constReturns a deep copy of this `HttpHeaders`.

An HTTP request.

Fields
HttpMethod method
string url
HttpHeaders headers
ubyte[] body
Duration operationTimeout
Duration connectTimeout
uint maxRedirects
Methods
HttpRequest withHeader(string name, string value) constReturns a copy of this request with an additional/replaced header.
HttpRequest withBody(const(ubyte)[] data) constReturns a copy of this request with a body.
HttpRequest withOperationTimeout(Duration d) constReturns a copy of this request with an operation timeout.
HttpRequest withConnectTimeout(Duration d) constReturns a copy of this request with a connect timeout.
HttpRequest withMaxRedirects(uint max) constReturns a copy of this request with a redirect limit.
HttpRequest dup() constReturns a deep copy of this request.
Constructors
this(HttpMethod method, string url)Constructs a request with the given method and URL.

An HTTP response.

Fields
ushort statusCode
string reasonPhrase
HttpHeaders headers
ubyte[] body
Methods
bool isSuccess() constReturns true if `statusCode` is in the 2xx range.
string bodyAsString() constReturns the body as a string.
string header(string name, string defaultValue = "") constConvenience accessor for a header on the response.
interfaceHttpClient

Synchronous HTTP client interface.

Methods
HttpResponse request(ref const HttpRequest request)Performs an HTTP request and returns the full response.
void close()Releases any resources associated with the client.
structHttpFuture(T)

A future representing an asynchronously produced value.

Fields
private SharedState _state
Methods
bool isValid() @property constReturns true if this future refers to a valid asynchronous result.
bool ready()Returns true if the future is already completed.
void wait()Blocks until the future is completed.
T get()Blocks until completion, then returns the value or throws the stored error.
Constructors
Nested Templates
SharedState
structHttpPromise(T)

A promise that can be completed with a value or an error.

Fields
private SharedState _state
Methods
HttpPromise!T make()Creates a new promise.
HttpFuture!T future()Returns the future associated with this promise.
void succeed(T value)Completes the promise successfully.
void fail(Throwable error)Completes the promise with an error.

Asynchronous HTTP client interface.

Methods
HttpFuture!HttpResponse requestAsync(ref const HttpRequest request)Starts an HTTP request and returns a future for its response.
void close()Releases any resources associated with the client.