Class RESTRequest
- Namespace
- Glitch9.IO.Networking.RESTApi
This class is used to create a http request. It holds the endpoint, headers, form data and the request options. It is used to send a request to the server and receive a response.
public class RESTRequest
- Inheritance
-
RESTRequest
- Derived
- Inherited Members
- Extension Methods
Constructors
RESTRequest()
public RESTRequest()
RESTRequest(string, RequestOptions)
public RESTRequest(string url, RequestOptions options = null)
Parameters
urlstringoptionsRequestOptions
Fields
_options
protected readonly RequestOptions _options
Field Value
Properties
Endpoint
The endpoint of the request. This is the url of the server where the request will be sent.
public string Endpoint { get; set; }
Property Value
Form
Optional. The form data of the request. This is used to send data to the server in a form format.
public WWWForm Form { get; set; }
Property Value
- WWWForm
HasBody
Indicates if the request has a body or not. This is used to determine if the request should be sent with a body or not.
public virtual bool HasBody { get; }
Property Value
Headers
The headers of the request. This is used to send additional information to the server. The headers can be used to set the content type, authorization, etc.
public List<RESTHeader> Headers { get; protected set; }
Property Value
Id
The unique identifier of the request.
public string Id { get; }
Property Value
IgnoreLogs
Indicates if the request should be logged or not.
public bool IgnoreLogs { get; }
Property Value
IsStreamRequest
Returns true if the request is a stream request.
public bool IsStreamRequest { get; }
Property Value
MIMEType
The content type of the request. Default is Json
public virtual MIMEType MIMEType { get; }
Property Value
MaxRetry
The number of retries of the request. Default is 3
public int MaxRetry { get; }
Property Value
OutputAudioFormat
The audio format of the expected audio response. Default is null.
public AudioFormat OutputAudioFormat { get; }
Property Value
OutputPath
Optional. If this is set, the response data will be saved to this path as a file. Supported formats:
- TODO: Add supported formats
public string OutputPath { get; }
Property Value
RetryDelayInSec
Seconds of delay to make a retry. Default is 1
public float RetryDelayInSec { get; }
Property Value
Sender
Optional. The local sender of the request.
public string Sender { get; }
Property Value
StreamHandler
If this is set, it means you are requesting a stream response from the server.
public IStreamHandler StreamHandler { get; }
Property Value
Timeout
The custom timeout for the request.
public TimeSpan? Timeout { get; set; }
Property Value
Token
Optional. External cancellation token for the request. This is used to cancel the request from outside the request.
public CancellationToken? Token { get; set; }
Property Value
WebRequest
Holds a reference to a UnityWebRequest object. This is used to send the request to the server and receive a response.
public UnityWebRequest WebRequest { get; set; }
Property Value
- UnityWebRequest
Methods
AddHeader(RESTHeader)
Adds a header to the request.
public void AddHeader(RESTHeader header)
Parameters
headerRESTHeader
CancelRequest()
Cancels this request (only if a cancellation token is set). This will throw a OperationCanceledException if the request is cancelled.
public void CancelRequest()
Equals(RESTRequest)
protected bool Equals(RESTRequest other)
Parameters
otherRESTRequest
Returns
Equals(object)
Determines whether the specified object is equal to the current object.
public override bool Equals(object obj)
Parameters
objobjectThe object to compare with the current object.
Returns
GetHashCode()
Serves as the default hash function.
public override int GetHashCode()
Returns
- int
A hash code for the current object.
Temp(string, RequestOptions)
Creates a RESTRequest with the given endpoint. This is used when you are sending a request with empty body.
public static RESTRequest Temp(string url, RequestOptions options = null)
Parameters
urlstringoptionsRequestOptions
Returns
Operators
operator ==(RESTRequest, RESTRequest)
public static bool operator ==(RESTRequest left, RESTRequest right)
Parameters
leftRESTRequestrightRESTRequest
Returns
operator !=(RESTRequest, RESTRequest)
public static bool operator !=(RESTRequest left, RESTRequest right)
Parameters
leftRESTRequestrightRESTRequest