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.
enum HttpMethod
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.enumHttpMethod
Standard HTTP methods.
GET
HEAD
POST
PUT
DELETE
OPTIONS
TRACE
CONNECT
PATCH
structHttpHeaders
A case-insensitive header map.
Header names are normalized to lower case for lookups.
Fields
private string[string] _valuesMethods
void opIndexAssign(string value, string name)Map-like assignment: `headers["name"] = "value"`.void opIndexAssign(typeof(null), string name)Map-like delete: `headers["name"] = null`.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.void remove(string name)Removes a header if present.structHttpRequest
An HTTP request.
Fields
HttpMethod methodstring urlHttpHeaders headersubyte[] bodyDuration operationTimeoutDuration connectTimeoutuint maxRedirectsMethods
HttpRequest withHeader(string name, string value) constReturns a copy of this request with an additional/replaced header.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.Constructors
this(HttpMethod method, string url)Constructs a request with the given method and URL.structHttpResponse
An HTTP response.
Methods
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 _stateMethods
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
this(SharedState state)Nested Templates
SharedStatestructHttpPromise(T)
A promise that can be completed with a value or an error.
Fields
private SharedState _stateMethods
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.interfaceAsyncHttpClient
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.