Table of Contents

Class RESTRequest

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

url string
options RequestOptions

Fields

_options

protected readonly RequestOptions _options

Field Value

RequestOptions

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

string

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

bool

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

List<RESTHeader>

Id

The unique identifier of the request.

public string Id { get; }

Property Value

string

IgnoreLogs

Indicates if the request should be logged or not.

public bool IgnoreLogs { get; }

Property Value

bool

IsStreamRequest

Returns true if the request is a stream request.

public bool IsStreamRequest { get; }

Property Value

bool

MIMEType

The content type of the request. Default is Json

public virtual MIMEType MIMEType { get; }

Property Value

MIMEType

MaxRetry

The number of retries of the request. Default is 3

public int MaxRetry { get; }

Property Value

int

OutputAudioFormat

The audio format of the expected audio response. Default is null.

public AudioFormat OutputAudioFormat { get; }

Property Value

AudioFormat

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

string

RetryDelayInSec

Seconds of delay to make a retry. Default is 1

public float RetryDelayInSec { get; }

Property Value

float

Sender

Optional. The local sender of the request.

public string Sender { get; }

Property Value

string

StreamHandler

If this is set, it means you are requesting a stream response from the server.

public IStreamHandler StreamHandler { get; }

Property Value

IStreamHandler

Timeout

The custom timeout for the request.

public TimeSpan? Timeout { get; set; }

Property Value

TimeSpan?

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

CancellationToken?

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

header RESTHeader

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

other RESTRequest

Returns

bool

Equals(object)

Determines whether the specified object is equal to the current object.

public override bool Equals(object obj)

Parameters

obj object

The object to compare with the current object.

Returns

bool

true if the specified object is equal to the current object; otherwise, false.

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

url string
options RequestOptions

Returns

RESTRequest

Operators

operator ==(RESTRequest, RESTRequest)

public static bool operator ==(RESTRequest left, RESTRequest right)

Parameters

left RESTRequest
right RESTRequest

Returns

bool

operator !=(RESTRequest, RESTRequest)

public static bool operator !=(RESTRequest left, RESTRequest right)

Parameters

left RESTRequest
right RESTRequest

Returns

bool