Class Request
public class Request
- Inheritance
-
Request
- Inherited Members
Constructors
Request(string)
Initializes a new instance of the Request class with the specified URL.
public Request(string url)
Parameters
url
stringThe URL to send the request to.
Request(string, HttpMethod)
Initializes a new instance of the Request class with the specified URL and HTTP method.
public Request(string url, HttpMethod method)
Parameters
url
stringThe URL to send the request to.
method
HttpMethodThe HTTP method to use for the request.
Properties
Body
Gets the JSON body content of the request.
public object Body { get; }
Property Value
ContentHeaders
Gets the content headers.
public Dictionary<string, string> ContentHeaders { get; }
Property Value
ContentType
Gets the content type of the request.
public string ContentType { get; }
Property Value
DocumentBody
Gets the binary document content of the request.
public byte[] DocumentBody { get; }
Property Value
- byte[]
DocumentFileName
Gets the name of the binary document file.
public string? DocumentFileName { get; }
Property Value
Method
Gets the HTTP method to use for the request.
public HttpMethod Method { get; }
Property Value
QueryParams
Gets the query parameters.
public Dictionary<string, string> QueryParams { get; }
Property Value
RequestHeaders
Gets the request headers.
public Dictionary<string, string> RequestHeaders { get; }
Property Value
URL
Gets the URL to send the request to.
public string URL { get; }
Property Value
Methods
AcceptJson()
Adds an "Accept" header with the value "application/json" to the request.
public Request AcceptJson()
Returns
- Request
Instance
AddByteBody(byte[], string?)
Adds a byte[] to the request content.
public Request AddByteBody(byte[] document, string? fileName)
Parameters
Returns
- Request
Instance
AddContentHeader(string, string)
Adds a content header to the request
public Request AddContentHeader(string key, string value)
Parameters
Returns
- Request
Instance
AddContentHeaders(Dictionary<string, string>)
Adds multiple content headers from a dictionary of key-value pairs to the request.
public Request AddContentHeaders(Dictionary<string, string> headers)
Parameters
headers
Dictionary<string, string>Content headers in dictionary.
Returns
- Request
Instance
AddHeader(string, string)
Adds a header to the request.
public Request AddHeader(string key, string value)
Parameters
Returns
- Request
Instance
AddHeaders(Dictionary<string, string>)
Adds multiple headers from a dictionary of key-value pairs to the request.
public Request AddHeaders(Dictionary<string, string> headers)
Parameters
headers
Dictionary<string, string>Headers in dictionary.
Returns
- Request
Instance
AddJsonBody(object)
Adds a JSON body to the request content.
public Request AddJsonBody(object body)
Parameters
body
objectThe JSON body content.
Returns
- Request
Instance
AddQueryParam(string, string)
Adds a query parameter to the request.
public Request AddQueryParam(string key, string value)
Parameters
Returns
- Request
Instance
AddQueryParams(Dictionary<string, string>)
Adds multiple content headers from a dictionary of key-value pairs to the request.
public Request AddQueryParams(Dictionary<string, string> queryParams)
Parameters
queryParams
Dictionary<string, string>Query parameters in dictionary.
Returns
- Request
Instance
RunBinaryRaw<T>()
Executes the HTTP request by sending the raw binary content directly in the request body, without using multipart encoding. This method is ideal for APIs expecting direct binary content, equivalent to Postman's "Binary" body type.
public Task<Result<T>> RunBinaryRaw<T>()
Returns
- Task<Result<T>>
A Result<T> object containing the deserialized response, the HTTP status code, and any error message if the request fails.
Type Parameters
T
The type of the expected response.
RunDocument<T>()
Executes the HTTP request and returns the response content as a byte array.
public Task<Result<T>> RunDocument<T>()
Returns
Type Parameters
T
The type of the response expected from the request.
RunGetBytes()
Executes the HTTP request that will return a byte array.
public Task<Result<byte[]>> RunGetBytes()
Returns
- Task<Result<byte[]>>
A Result<T> object containing the response content as a byte array, the status code of the response, and any error message if the request fails.
Run<T>()
Executes the HTTP request with the JSON body content included.
public Task<Result<T>> Run<T>()
Returns
Type Parameters
T
The type of the response expected from the request.
SetContentType(string)
Sets the content type of the request.
public Request SetContentType(string contentType)
Parameters
contentType
stringThe content type of the request.
Returns
- Request
Instance