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
- object
- HttpRequestScope
Constructors
HttpRequestScope(HttpRestClient)
Initializes a new instance of the HttpRequestScope class.
public HttpRequestScope(HttpRestClient client)Parameters
clientHttpRestClient- The HttpRestClient associated with this scope.
Exceptions
- ArgumentNullException
- Thrown if the
clientargument isnull>.
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
scopedActionFunc<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
scopedActionisnull>.
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
scopedFunctionFunc<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
scopedFunctionisnull>.
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
Returns
- HttpRequestScope
- The same HttpRequestScope instance for fluent chaining.
Exceptions
- ArgumentNullException
- Thrown if the
nameargument isnull>.
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
Returns
- HttpRequestScope
- The same HttpRequestScope instance for fluent chaining.
Exceptions
- ArgumentNullException
- Thrown if the
nameargument isnull.
UnsetHeader(string)
Specifies that a header should be removed from requests sent within this scope.
public HttpRequestScope UnsetHeader(string name)Parameters
namestring- The header name to remove.
Returns
- HttpRequestScope
- The same HttpRequestScope instance for fluent chaining.
Exceptions
- ArgumentNullException
- Thrown if the
nameargument isnull>.
UnsetProperty(string)
Specifies that a property should be removed from requests sent within this scope.
public HttpRequestScope UnsetProperty(string name)Parameters
namestring- The name of the property.
Returns
- HttpRequestScope
- The same HttpRequestScope instance for fluent chaining.
Exceptions
- ArgumentNullException
- Thrown if the
nameargument isnull>.
