HttpRequestScope Class

Namespace
Kampute.HttpClient
Assembly
  • Kampute.HttpClient.dll

Definition

Represents a scope of properties and headers that can be used for HttpRestClient requests.
public sealed class HttpRequestScope
Inheritance

Constructors

HttpRequestScope(HttpRestClient)

Initializes a new instance of the HttpRequestScope class.
public HttpRequestScope(HttpRestClient client)

Parameters

client HttpRestClient
The HttpRestClient associated with this scope.

Exceptions

ArgumentNullException
Thrown if the client argument is null>.

Properties

Client

Gets the HttpRestClient associated with this scope.
public HttpRestClient Client { get; }

Property Value

HttpRestClient
The HttpRestClient that is used to send HTTP requests within this scope.

Headers

Gets the collection of headers that are configured to be applied to the HTTP requests sent within this scope.
public IReadOnlyCollection<KeyValuePair<string, string>> Headers { get; }

Property Value

IReadOnlyCollection<KeyValuePair<string, string>>
The read-only collection of key-value pairs representing the headers to be applied to the HTTP requests sent within this scope.

Properties

Gets the collection of properties that are configured to be applied to the HTTP requests sent within this scope.
public IReadOnlyCollection<KeyValuePair<string, object>> Properties { get; }

Property Value

IReadOnlyCollection<KeyValuePair<string, object>>
The read-only collection of key-value pairs representing the properties to be applied to the HTTP requests sent within this scope.

Methods

PerformAsync(Func<HttpRestClient, Task>)

Executes a task within the configured scope, applying all set properties and headers to requests made by the client during the execution of the task.
public Task PerformAsync(Func<HttpRestClient, Task> scopedAction)

Parameters

scopedAction Func<HttpRestClient, Task>
The asynchronous action to execute, which involves HTTP requests that will include the configured properties and headers.

Returns

Task
A task representing the asynchronous operation.

Exceptions

ArgumentNullException
Thrown if the scopedAction is null>.

PerformAsync<T>(Func<HttpRestClient, Task<T>>)

Executes a task within the configured scope, applying all set properties and headers to requests made by the client during the execution of the task, and returns a result of type T.
public Task<T> PerformAsync<T>(Func<HttpRestClient, Task<T>> scopedFunction)

Type Parameters

T
The type of the result returned by the scoped action.

Parameters

scopedFunction Func<HttpRestClient, Task<T>>
The asynchronous function to execute, which involves HTTP requests that will include the configured properties and headers.

Returns

Task<T>
A task representing the asynchronous operation with a result of type T.

Exceptions

ArgumentNullException
Thrown if the scopedFunction is null>.

SetHeader(string, string)

Specifies that a header should be used with the specified value for requests sent within this scope.
public HttpRequestScope SetHeader(string name, string value)

Parameters

name string
The name of the header.
value string
The value of the header.

Returns

HttpRequestScope
The same HttpRequestScope instance for fluent chaining.

Exceptions

ArgumentNullException
Thrown if the name argument is null>.

SetProperty(string, object)

Specifies that a property should be used with the specified value for requests sent within this scope.
public HttpRequestScope SetProperty(string name, object value)

Parameters

name string
The name of the property.
value object
The value of the property.

Returns

HttpRequestScope
The same HttpRequestScope instance for fluent chaining.

Exceptions

ArgumentNullException
Thrown if the name argument is null.

UnsetHeader(string)

Specifies that a header should be removed from requests sent within this scope.
public HttpRequestScope UnsetHeader(string name)

Parameters

name string
The header name to remove.

Returns

HttpRequestScope
The same HttpRequestScope instance for fluent chaining.

Exceptions

ArgumentNullException
Thrown if the name argument is null>.

UnsetProperty(string)

Specifies that a property should be removed from requests sent within this scope.
public HttpRequestScope UnsetProperty(string name)

Parameters

name string
The name of the property.

Returns

HttpRequestScope
The same HttpRequestScope instance for fluent chaining.

Exceptions

ArgumentNullException
Thrown if the name argument is null>.