Table of Contents

Class HttpExecutable

Namespace
Microsoft.Accordant
Assembly
Accordant.Operations.Http.dll

This class sends requests encoded through HttpRequest objects using an HttpClient retrieved via Target<T>(). The results are wrapped in HttpResponse objects and returned to the caller.

public class HttpExecutable
Inheritance
HttpExecutable
Inherited Members

Constructors

HttpExecutable()

Constructs an instance of this class, taking in an optional pair of payload serializer and deserializer lambdas.

public HttpExecutable()

Properties

Default

Returns the default instance of this class.

The default instance serializes payloads using JsonSerializer class, encoded as a UTF8 string with ContentType set to 'application/json'.

The default instance deserializes the payload assuming the string is encoded as a JSON object. It uses JsonSerializer to deserialize the payload, treating property names as case insensitive.

public static HttpExecutable Default { get; set; }

Property Value

HttpExecutable

EmitCorrelationId

Indicates whether correlation id should be emitted in HTTP diagnostic logs. Correlation Ids can be particularly helpful when debugging logs of requests made concurrently with each other.

public bool EmitCorrelationId { get; set; }

Property Value

bool

EmitDiagnosticLogs

This flag controls whether this class emits diagnostic logs when executing HTTP requests.

public bool EmitDiagnosticLogs { get; set; }

Property Value

bool

LogLineEmitter

This classes uses this lambda to emit log lines.

public Action<string> LogLineEmitter { get; set; }

Property Value

Action<string>

MaxLogLineLength

The maximum length of a log line after which it is trimmed. Defaults to 2KB.

public int MaxLogLineLength { get; set; }

Property Value

int

PayloadDeserializer

The payload deserializer takes in a string read from the HttpResponseMessage object along with the expected type of the response and returns a deserialized object.

public Func<HttpContent, Type, object> PayloadDeserializer { get; set; }

Property Value

Func<HttpContent, Type, object>

PayloadSerializer

The payload serializer takes in an object and returns a StringContent object which is used to pass the payload as the body in an HttpRequestMessage object.

public Func<object, HttpContent> PayloadSerializer { get; set; }

Property Value

Func<object, HttpContent>

TrimLogLinesIfTooLong

Whether to trim log lines if there length exceeds MaxLogLineLength

public bool TrimLogLinesIfTooLong { get; set; }

Property Value

bool

Methods

BytesToHigherUnits(long)

public static string BytesToHigherUnits(long numBytes)

Parameters

numBytes long

Returns

string

ExecuteAsync(TestingContext, HttpRequest, Dictionary<string, string>)

This method takes an http request with no payload and returns an http response with no payload.

public Task<HttpResponse> ExecuteAsync(TestingContext context, HttpRequest httpRequest, Dictionary<string, string> additionalRequestHeaders = null)

Parameters

context TestingContext
httpRequest HttpRequest
additionalRequestHeaders Dictionary<string, string>

Returns

Task<HttpResponse>

ExecuteAsync<TEmpty, TResponse>(TestingContext, HttpRequest, Func<int, bool>, Dictionary<string, string>)

This method takes an http request with no payload and returns an http response containing a payload of type TResponse.

public Task<HttpResponse<TResponse>> ExecuteAsync<TEmpty, TResponse>(TestingContext context, HttpRequest httpRequest, Func<int, bool> shouldParsePayload = null, Dictionary<string, string> additionalRequestHeaders = null) where TEmpty : Unit

Parameters

context TestingContext
httpRequest HttpRequest
shouldParsePayload Func<int, bool>
additionalRequestHeaders Dictionary<string, string>

Returns

Task<HttpResponse<TResponse>>

Type Parameters

TEmpty
TResponse

ExecuteAsync<TRequest, TEmpty>(TestingContext, HttpRequest<TRequest>, Dictionary<string, string>)

This method takes an http request with a payload of type TRequest and returns an http response without any payload.

public Task<HttpResponse> ExecuteAsync<TRequest, TEmpty>(TestingContext context, HttpRequest<TRequest> httpRequest, Dictionary<string, string> additionalRequestHeaders = null) where TEmpty : Unit

Parameters

context TestingContext
httpRequest HttpRequest<TRequest>
additionalRequestHeaders Dictionary<string, string>

Returns

Task<HttpResponse>

Type Parameters

TRequest
TEmpty

ExecuteAsync<TRequest, TResponse>(TestingContext, HttpRequest<TRequest>, Func<int, bool>, Dictionary<string, string>)

This method takes an http request with a payload of type TRequest and returns an http response containing a payload of type TResponse.

public Task<HttpResponse<TResponse>> ExecuteAsync<TRequest, TResponse>(TestingContext context, HttpRequest<TRequest> httpRequest, Func<int, bool> shouldParsePayload = null, Dictionary<string, string> additionalRequestHeaders = null)

Parameters

context TestingContext
httpRequest HttpRequest<TRequest>
shouldParsePayload Func<int, bool>
additionalRequestHeaders Dictionary<string, string>

Returns

Task<HttpResponse<TResponse>>

Type Parameters

TRequest
TResponse