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
RestRequest(Uri, Method)
public RestRequest(Uri resource, Method method = Method.Get)
Parameters
resource
Urimethod
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
AlwaysMultipartFormData
Always send a multipart/form-data request - even when no Files are present.
public bool AlwaysMultipartFormData { get; set; }
Property Value
Attempts
How many attempts were made to send this Request
public int Attempts { get; }
Property Value
Remarks
This number is incremented each time the RestClient sends the request.
CompletionOption
Completion option for HttpClient
public HttpCompletionOption CompletionOption { get; set; }
Property Value
Files
Container of all the files to be uploaded with the request.
public IReadOnlyCollection<FileParameter> Files { get; }
Property Value
FormBoundary
public string? FormBoundary { get; set; }
Property Value
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
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
OnAfterRequest
When supplied, the function will be called after the request is complete
public Func<HttpResponseMessage, ValueTask>? OnAfterRequest { get; set; }
Property Value
OnBeforeDeserialization
When supplied, the function will be called before calling the deserializer
public Action<RestResponse>? OnBeforeDeserialization { get; set; }
Property Value
OnBeforeRequest
When supplied, the function will be called before making a request
public Func<HttpRequestMessage, ValueTask>? OnBeforeRequest { get; set; }
Property Value
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
RequestFormat
Serializer to use when writing request bodies.
public DataFormat RequestFormat { get; set; }
Property Value
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
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
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
Timeout
Custom request timeout
public int Timeout { get; set; }
Property Value
Methods
AddParameter(Parameter)
Adds a parameter object to the request parameters
public RestRequest AddParameter(Parameter parameter)
Parameters
parameter
ParameterParameter to add
Returns
RemoveParameter(Parameter)
Removes a parameter object from the request parameters
public RestRequest RemoveParameter(Parameter parameter)
Parameters
parameter
ParameterParameter to remove