Table of Contents

Class RestRequest

Namespace
RestSharp
Assembly
RestSharp.dll

Container for data used to make requests

public class RestRequest
Inheritance
RestRequest
Derived
Inherited Members
Extension Methods

Constructors

RestRequest()

Default constructor

public RestRequest()

RestRequest(string?, Method)

public RestRequest(string? resource, Method method = Method.Get)

Parameters

resource string
method Method

RestRequest(Uri, Method)

public RestRequest(Uri resource, Method method = Method.Get)

Parameters

resource Uri
method Method

Properties

AdvancedResponseWriter

Set this to handle the response stream yourself, based on the response details

public Func<HttpResponseMessage, RestResponse>? AdvancedResponseWriter { get; init; }

Property Value

Func<HttpResponseMessage, RestResponse>

AlwaysMultipartFormData

Always send a multipart/form-data request - even when no Files are present.

public bool AlwaysMultipartFormData { get; set; }

Property Value

bool

Attempts

How many attempts were made to send this Request

public int Attempts { get; }

Property Value

int

Remarks

This number is incremented each time the RestClient sends the request.

CompletionOption

Completion option for HttpClient

public HttpCompletionOption CompletionOption { get; set; }

Property Value

HttpCompletionOption

Files

Container of all the files to be uploaded with the request.

public IReadOnlyCollection<FileParameter> Files { get; }

Property Value

IReadOnlyCollection<FileParameter>

FormBoundary

public string? FormBoundary { get; set; }

Property Value

string

Method

Determines what HTTP method to use for this request. Supported methods: GET, POST, PUT, DELETE, HEAD, OPTIONS Default is GET

public Method Method { get; set; }

Property Value

Method

MultipartFormQuoteParameters

When set to true, parameters in a multipart form data requests will be enclosed in quotation marks. Default is false. Enable it if the remote endpoint requires parameters to be in quotes (for example, FreshDesk API).

public bool MultipartFormQuoteParameters { get; set; }

Property Value

bool

OnAfterRequest

When supplied, the function will be called after the request is complete

public Func<HttpResponseMessage, ValueTask>? OnAfterRequest { get; set; }

Property Value

Func<HttpResponseMessage, ValueTask>

OnBeforeDeserialization

When supplied, the function will be called before calling the deserializer

public Action<RestResponse>? OnBeforeDeserialization { get; set; }

Property Value

Action<RestResponse>

OnBeforeRequest

When supplied, the function will be called before making a request

public Func<HttpRequestMessage, ValueTask>? OnBeforeRequest { get; set; }

Property Value

Func<HttpRequestMessage, ValueTask>

Parameters

Container of all HTTP parameters to be passed with the request. See AddParameter() for explanation of the types of parameters that can be passed

public ParametersCollection Parameters { get; }

Property Value

ParametersCollection

RequestFormat

Serializer to use when writing request bodies.

public DataFormat RequestFormat { get; set; }

Property Value

DataFormat

Resource

The Resource URL to make the request against. Tokens are substituted with UrlSegment parameters and match by name. Should not include the scheme or domain. Do not include leading slash. Combined with RestClient.BaseUrl to assemble final URL: {BaseUrl}/{Resource} (BaseUrl is scheme + domain, e.g. http://example.com)

public string Resource { get; set; }

Property Value

string

Examples

// example for url token replacement request.Resource = "Products/{ProductId}"; request.AddParameter("ProductId", 123, ParameterType.UrlSegment);

ResponseWriter

Set this to write response to Stream rather than reading into memory.

public Func<Stream, Stream?>? ResponseWriter { get; init; }

Property Value

Func<Stream, Stream>

RootElement

Used by the default deserializers to determine where to start deserializing from. Can be used to skip container or root elements that do not have corresponding deserialzation targets.

public string? RootElement { get; set; }

Property Value

string

Timeout

Custom request timeout

public int Timeout { get; set; }

Property Value

int

Methods

AddParameter(Parameter)

Adds a parameter object to the request parameters

public RestRequest AddParameter(Parameter parameter)

Parameters

parameter Parameter

Parameter to add

Returns

RestRequest

RemoveParameter(Parameter)

Removes a parameter object from the request parameters

public RestRequest RemoveParameter(Parameter parameter)

Parameters

parameter Parameter

Parameter to remove

Returns

RestRequest