RestSharp
Allows "basic access authentication" for HTTP requests.
Encoding can be specified depending on what your server expect (see https://stackoverflow.com/a/7243567).
UTF-8 is used by default but some servers might expect ISO-8859-1 encoding.
JSON WEB TOKEN (JWT) Authenticator class.
https://tools.ietf.org/html/draft-ietf-oauth-json-web-token
Set the new bearer token so the request gets the new header value
The set of characters that are unreserved in RFC 2396 but are NOT unreserved in RFC 3986.
Generates a random 16-byte lowercase alphanumeric string.
Generates a timestamp based on the current elapsed seconds since '01/01/1970 0000 GMT"
Generates a timestamp based on the elapsed seconds of a given time since '01/01/1970 0000 GMT"
A specified point in time.
URL encodes a string based on section 5.1 of the OAuth spec.
Namely, percent encoding with [RFC3986], avoiding unreserved characters,
upper-casing hexadecimal characters, and UTF-8 encoding for text value pairs.
The value to escape.
The escaped value.
The method is supposed to take on
RFC 3986 behavior if certain elements are present in a .config file. Even if this
actually worked (which in my experiments it doesn't), we can't rely on every
host actually having this configuration element present.
URL encodes a string based on section 5.1 of the OAuth spec.
Namely, percent encoding with [RFC3986], avoiding unreserved characters,
upper-casing hexadecimal characters, and UTF-8 encoding for text value pairs.
Sorts a collection of key-value pairs by name, and then value if equal,
concatenating them into a single string. This string should be encoded
prior to, or after normalization is run.
Sorts a by name, and then value if equal.
A collection of parameters to sort
A sorted parameter collection
Creates a request URL suitable for making OAuth requests.
Resulting URLs must exclude port 80 or port 443 when accompanied by HTTP and HTTPS, respectively.
Resulting URLs must be lower case.
The original request URL
Creates a request elements concatenation value to send with a request.
This is also known as the signature base.
The request HTTP method type
The request URL
The request parameters
A signature base string
Creates a signature value given a signature base and the consumer secret.
This method is used when the token secret is currently unknown.
The hashing method
The signature base
The consumer key
Creates a signature value given a signature base and the consumer secret.
This method is used when the token secret is currently unknown.
The hashing method
The treatment to use on a signature value
The signature base
The consumer key
Creates a signature value given a signature base and the consumer secret and a known token secret.
The hashing method
The treatment to use on a signature value
The signature base
The consumer secret
The token secret
A class to encapsulate OAuth authentication flow.
Generates an OAuth signature to pass to an
for the purpose of requesting an
unauthorized request token.
The HTTP method for the intended request
Any existing, non-OAuth query parameters desired in the request
Generates an OAuth signature to pass to the
for the purpose of exchanging a request token
for an access token authorized by the user at the Service Provider site.
The HTTP method for the intended request
Any existing, non-OAuth query parameters desired in the request
Generates an OAuth signature to pass to an
for the purpose of exchanging user credentials
for an access token authorized by the user at the Service Provider site.
The HTTP method for the intended request
Any existing, non-OAuth query parameters desired in the request
RFC: The OAuth 1.0 Protocol
The OAuth 2 authenticator using the authorization request header field.
Based on http://tools.ietf.org/html/draft-ietf-oauth-v2-10#section-5.1.1
Initializes a new instance of the class.
The access token.
Initializes a new instance of the class.
The access token.
The token type.
The OAuth 2 authenticator using URI query parameter.
Based on http://tools.ietf.org/html/draft-ietf-oauth-v2-10#section-5.1.2
Initializes a new instance of the class.
The access token.
Types of parameters that can be added to requests
Cookie parameter
Data formats
HTTP method to use when making requests
Format strings for commonly-used date formats
.NET format string for ISO 8601 date format
.NET format string for roundtrip date format
Status for responses (surprised?)
Extension method overload!
Read a stream into a byte array
Stream to read
byte[]
Reflection extensions
Retrieve an attribute from a member (property)
Type of attribute to retrieve
Member to retrieve attribute from
Retrieve an attribute from a type
Type of attribute to retrieve
Type to retrieve attribute from
Checks a type to see if it derives from a raw generic (e.g. List[[]])
Find a value from a System.Enum by trying several possible variants
of the string value of the enum.
Type of enum
Value for which to search
The culture used to calculate the name variants
Uses Uri.EscapeDataString() based on recommendations on MSDN
http://blogs.msdn.com/b/yangxind/archive/2006/11/09/don-t-use-net-system-uri-unescapedatastring-in-url-decoding.aspx
Remove underscores from a string
String to process
string
Converts a string to pascal case
String to convert
string
Converts a string to pascal case with the option to remove underscores
String to convert
Option to remove underscores
Converts a string to camel case
String to convert
String
Return possible variants of a name for name matching.
String to convert
The culture to use for conversion
IEnumerable<string>
Body parameter data type
Custom content encoding
Container for files to be uploaded with requests
Provides raw data for file
Name of the file to use when uploading
MIME content type of file
Name of the parameter
Creates a file parameter from an array of bytes.
The parameter name to use in the request.
The data to use as the file's contents.
The filename to use in the request.
The content type to use in the request.
The
Creates a file parameter from an array of bytes.
The parameter name to use in the request.
Delegate that will be called with the request stream so you can write to it..
The filename to use in the request.
Optional: parameter content type, default is "application/g-zip"
The using the default content type.
Instantiates an HTTP parameter instance (QueryString for GET, DELETE, OPTIONS and HEAD; Encoded form for POST and PUT)
Name of the parameter
Value of the parameter
Encode the value or not, default true
Instantiates a header parameter
Parameter name
Parameter value
Parameter container for REST requests
Parameter container for REST requests
MIME content type of the parameter
Return a human-readable representation of this parameter
String
Instantiates a new query parameter instance that will be added to the request URL as {name}={value} part of the query string.
Parameter name
Parameter value
Optional: encode the value, default is true
Instantiates a new query parameter instance that will be added to the request URL part of the query string.
The request resource should have a placeholder {name} that will be replaced with the parameter value when the request is made.
Parameter name
Parameter value
Optional: encode the value, default is true
Container for data used to make requests
Default constructor
Always send a multipart/form-data request - even when no Files are present.
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).
Container of all HTTP parameters to be passed with the request.
See AddParameter() for explanation of the types of parameters that can be passed
Container of all the files to be uploaded with the request.
Determines what HTTP method to use for this request. Supported methods: GET, POST, PUT, DELETE, HEAD, OPTIONS
Default is GET
Custom request timeout
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)
// example for url token replacement
request.Resource = "Products/{ProductId}";
request.AddParameter("ProductId", 123, ParameterType.UrlSegment);
Serializer to use when writing request bodies.
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.
When supplied, the function will be called before calling the deserializer
When supplied, the function will be called before making a request
When supplied, the function will be called after the request is complete
How many attempts were made to send this Request
This number is incremented each time the RestClient sends the request.
Completion option for
Set this to write response to Stream rather than reading into memory.
Set this to handle the response stream yourself, based on the response details
Adds a parameter object to the request parameters
Parameter to add
Removes a parameter object from the request parameters
Parameter to remove
Adds a HTTP parameter to the request (QueryString for GET, DELETE, OPTIONS and HEAD; Encoded form for POST and PUT)
Name of the parameter
Value of the parameter
Encode the value or not, default true
This request
Adds a HTTP parameter to the request (QueryString for GET, DELETE, OPTIONS and HEAD; Encoded form for POST and PUT)
Request instance
Name of the parameter
Value of the parameter
Encode the value or not, default true
This request
Adds or updates a HTTP parameter to the request (QueryString for GET, DELETE, OPTIONS and HEAD; Encoded form for POST and PUT)
Request instance
Name of the parameter
Value of the parameter
Encode the value or not, default true
This request
Adds or updates a HTTP parameter to the request (QueryString for GET, DELETE, OPTIONS and HEAD; Encoded form for POST and PUT)
Request instance
Name of the parameter
Value of the parameter
Encode the value or not, default true
This request
Adds a URL segment parameter to the request. The resource URL must have a placeholder for the parameter for it to work.
For example, if you add a URL segment parameter with the name "id", the resource URL should contain {id} in its path.
Request instance
Name of the parameter, must be matching a placeholder in the resource URL as {name}
Value of the parameter
Encode the value or not, default true
Adds a URL segment parameter to the request. The resource URL must have a placeholder for the parameter for it to work.
For example, if you add a URL segment parameter with the name "id", the resource URL should contain {id} in its path.
Request instance
Name of the parameter, must be matching a placeholder in the resource URL as {name}
Value of the parameter
Encode the value or not, default true
Adds a query string parameter to the request. The request resource should not contain any placeholders for this parameter.
The parameter will be added to the request URL as a query string using name=value format.
Request instance
Parameter name
Parameter value
Encode the value or not, default true
Adds a query string parameter to the request. The request resource should not contain any placeholders for this parameter.
The parameter will be added to the request URL as a query string using name=value format.
Request instance
Parameter name
Parameter value
Encode the value or not, default true
Adds a header to the request. RestSharp will try to separate request and content headers when calling the resource.
Request instance
Header name
Header value
Adds a header to the request. RestSharp will try to separate request and content headers when calling the resource.
Request instance
Header name
Header value
Adds or updates the request header. RestSharp will try to separate request and content headers when calling the resource.
Existing header with the same name will be replaced.
Request instance
Header name
Header value
Adds or updates the request header. RestSharp will try to separate request and content headers when calling the resource.
Existing header with the same name will be replaced.
Request instance
Header name
Header value
Adds multiple headers to the request, using the key-value pairs provided.
Request instance
Collection of key-value pairs, where key will be used as header name, and value as header value
Adds or updates multiple headers to the request, using the key-value pairs provided. Existing headers with the same name will be replaced.
Request instance
Collection of key-value pairs, where key will be used as header name, and value as header value
Adds a parameter of a given type to the request. It will create a typed parameter instance based on the type argument.
It is not recommended to use this overload unless you must, as it doesn't provide any restrictions, and if the name-value-type
combination doesn't match, it will throw.
Request instance
Name of the parameter, must be matching a placeholder in the resource URL as {name}
Value of the parameter
Enum value specifying what kind of parameter is being added
Encode the value or not, default true
Adds or updates request parameter of a given type. It will create a typed parameter instance based on the type argument.
Parameter will be added or updated based on its name. If the request has a parameter with the same name, it will be updated.
It is not recommended to use this overload unless you must, as it doesn't provide any restrictions, and if the name-value-type
combination doesn't match, it will throw.
Request instance
Name of the parameter, must be matching a placeholder in the resource URL as {name}
Value of the parameter
Enum value specifying what kind of parameter is being added
Encode the value or not, default true
Adds or updates request parameter, given the parameter instance, for example or .
It will replace an existing parameter with the same name.
Request instance
Parameter instance
Adds or updates multiple request parameters, given the parameter instance, for example
or . Parameters with the same name will be replaced.
Request instance
Collection of parameter instances
Adds a file parameter to the request body. The file will be read from disk as a stream.
Request instance
Parameter name
Full path to the file
Optional: content type
Adds bytes to the request as file attachment
Request instance
Parameter name
File content as bytes
File name
Optional: content type. Default is "application/octet-stream"
Adds a file attachment to the request, where the file content will be retrieved from a given stream
Request instance
Parameter name
Function that returns a stream with the file content
File name
Optional: content type. Default is "application/octet-stream"
Adds a body parameter to the request
Request instance
Object to be used as the request body, or string for plain content
Optional: content type
Thrown if request body type cannot be resolved
This method will try to figure out the right content type based on the request data format and the provided content type
Adds a string body and figures out the content type from the data format specified. You can, for example, add a JSON string
using this method as request body, using DataFormat.Json/>
Request instance
String body
for the content
Adds a string body to the request using the specified content type.
Request instance
String body
Content type of the body
Adds a JSON body parameter to the request
Request instance
Object that will be serialized to JSON
Optional: content type. Default is "application/json"
Adds an XML body parameter to the request
Request instance
Object that will be serialized to XML
Optional: content type. Default is "application/xml"
Optional: XML namespace
Gets object properties and adds each property as a form data parameter
Request instance
Object to add as form data
Properties to include, or nothing to include everything
Used by the default deserializers to explicitly set which date format string to use when parsing dates.
Used by XmlDeserializer. If not specified, XmlDeserializer will flatten response by removing namespaces from
element names.
Container for data sent back from API including deserialized data
Type of data to deserialize to
Deserialized entity data
Container for data sent back from API
Base class for common properties shared by RestResponse and RestResponse[[T]]
Default constructor
The RestRequest that was made to get this RestResponse
Mainly for debugging if ResponseStatus is not OK
MIME content type of response
Length in bytes of the response content
Encoding of the response content
String representation of response content
HTTP response status code
Whether or not the response status code indicates success
Description of HTTP status returned
Response content
The URL that actually responded to the content (different from request if redirected)
HttpWebResponse.Server
Cookies returned by server with the response
Response headers returned by server with the response
Content headers returned by server with the response
Status of the request. Will return Error for transport errors.
HTTP errors will still return ResponseStatus.Completed, check StatusCode instead
Transport or other non-HTTP error generated while attempting request
The exception thrown during the request, if any
HTTP protocol version of the request
Root element of the serialized response content, only works if deserializer supports it
Assists with debugging responses by displaying in the debugger output
Client to translate RestRequests into Http requests and process response result
Executes the request asynchronously, authenticating if needed
Request to be executed
Cancellation token
A specialized method to download files as streams.
Pre-configured request instance.
The downloaded stream.
Content types that will be sent in the Accept header. The list is populated from the known serializers.
If you need to send something else by default, set this property to a different value.
Function to calculate the response status. By default, the status will be Completed if it was successful, or NotFound.
Creates an instance of RestClient using the default
Sets the BaseUrl property for requests made by this client instance
Sets the BaseUrl property for requests made by this client instance
Creates a new instance of RestSharp using the message handler provided. By default, HttpClient disposes the provided handler
when the client itself is disposed. If you want to keep the handler not disposed, set disposeHandler argument to false.
Message handler instance to use for HttpClient
Dispose the handler when disposing RestClient, true by default
Authenticator that will be used to populate request with necessary authentication data
Add a parameter to use on every request made with this client instance
Parameter to add
Replace the default serializer with a custom one
Function that returns the serializer instance
Replace the default serializer with a custom one
The type that implements
Allows to use a custom way to encode URL parameters
A delegate to encode URL parameters
client.UseUrlEncoder(s => HttpUtility.UrlEncode(s));
Allows to use a custom way to encode query parameters
A delegate to encode query parameters
client.UseUrlEncoder((s, encoding) => HttpUtility.UrlEncode(s, encoding));
Adds cookie to the cookie container.
Cookie name
Cookie value
Cookie path
Cookie domain, must not be an empty string
Executes a GET-style request asynchronously, authenticating if needed.
The response content then gets deserialized to T.
Target deserialization type
Request to be executed
Cancellation token
Deserialized response content
Executes a GET-style asynchronously, authenticating if needed
Request to be executed
Cancellation token
Executes a POST-style request asynchronously, authenticating if needed.
The response content then gets deserialized to T.
Target deserialization type
Request to be executed
The cancellation token
Deserialized response content
Executes a POST-style asynchronously, authenticating if needed
Request to be executed
Cancellation token
Executes a PUT-style request asynchronously, authenticating if needed.
The response content then gets deserialized to T.
Target deserialization type
Request to be executed
The cancellation token
Deserialized response content
Executes a PUP-style asynchronously, authenticating if needed
Request to be executed
Cancellation token
Executes the request asynchronously, authenticating if needed
Target deserialization type
Request to be executed
Cancellation token
Executes the request asynchronously, authenticating if needed
Request to be executed
Override the request method
Cancellation token
Executes the request asynchronously, authenticating if needed
Target deserialization type
Request to be executed
Override the request method
Cancellation token
Execute the request using GET HTTP method. Exception will be thrown if the request does not succeed.
The response data is deserialized to the Data property of the returned response object.
RestClient instance
The request
Cancellation token
Expected result type
Execute the request using POST HTTP method. Exception will be thrown if the request does not succeed.
The response data is deserialized to the Data property of the returned response object.
RestClient instance
The request
Cancellation token
Expected result type
Execute the request using PUT HTTP method. Exception will be thrown if the request does not succeed.
The response data is deserialized to the Data property of the returned response object.
RestClient instance
The request
Cancellation token
Expected result type
Execute the request using HEAD HTTP method. Exception will be thrown if the request does not succeed.
The response data is deserialized to the Data property of the returned response object.
RestClient instance
The request
Cancellation token
Expected result type
Execute the request using OPTIONS HTTP method. Exception will be thrown if the request does not succeed.
The response data is deserialized to the Data property of the returned response object.
RestClient instance
The request
Cancellation token
Expected result type
Execute the request using PATCH HTTP method. Exception will be thrown if the request does not succeed.
The response data is deserialized to the Data property of the returned response object.
RestClient instance
The request
Cancellation token
Expected result type
Execute the request using DELETE HTTP method. Exception will be thrown if the request does not succeed.
The response data is deserialized to the Data property of the returned response object.
RestClient instance
The request
Cancellation token
Expected result type
A specialized method to download files.
RestClient instance
Pre-configured request instance.
The downloaded file.
Reads a stream returned by the specified endpoint, deserializes each line to JSON and returns each object asynchronously.
It is required for each JSON object to be returned in a single line.
Sets the to only use JSON
The client instance
Sets the to only use XML
Calls the URL specified in the resource
parameter, expecting a JSON response back. Deserializes and returns the response.
RestClient instance
Resource URL
Cancellation token
Response object type
Serializes the request
object to JSON and makes a POST call to the resource specified in the resource
parameter.
Expects a JSON response back, deserializes it to TResponse
type and returns it.
RestClient instance
Resource URL
Request object, must be serializable to JSON
Cancellation token
Request object type
Response object type
Deserialized response object
Serializes the request
object to JSON and makes a POST call to the resource specified in the resource
parameter.
Expects no response back, just the status code.
RestClient instance
Resource URL
Request object, must be serializable to JSON
Cancellation token
Request object type
Response status code
Serializes the request
object to JSON and makes a PUT call to the resource specified in the resource
parameter.
Expects a JSON response back, deserializes it to TResponse
type and returns it.
RestClient instance
Resource URL
Request object, must be serializable to JSON
Cancellation token
Request object type
Response object type
Deserialized response object
Serializes the request
object to JSON and makes a PUT call to the resource specified in the resource
parameter.
Expects no response back, just the status code.
RestClient instance
Resource URL
Request object, must be serializable to JSON
Cancellation token
Request object type
Response status code
Adds a default HTTP parameter (QueryString for GET, DELETE, OPTIONS and HEAD; Encoded form for POST and PUT)
Used on every request made by this client instance
instance
Name of the parameter
Value of the parameter
This request
Adds a default parameter to the client options. There are four types of parameters:
- GetOrPost: Either a QueryString value or encoded form value based on method
- HttpHeader: Adds the name/value pair to the HTTP request's Headers collection
- UrlSegment: Inserted into URL if there is a matching url token e.g. {AccountId}
- RequestBody: Used by AddBody() (not recommended to use directly)
Used on every request made by this client instance
instance
Name of the parameter
Value of the parameter
The type of parameter to add
This request
Adds a default header to the RestClient. Used on every request made by this client instance.
instance
Name of the header to add
Value of the header to add
Adds default headers to the RestClient. Used on every request made by this client instance.
instance
Dictionary containing the Names and Values of the headers to add
Adds a default URL segment parameter to the RestClient. Used on every request made by this client instance.
instance
Name of the segment to add
Value of the segment to add
Adds a default URL query parameter to the RestClient. Used on every request made by this client instance.
instance
Name of the query parameter to add
Value of the query parameter to add
Explicit Host header value to use in requests independent from the request URI.
If null, default host value extracted from URI is used.
In general you would not need to set this directly. Used by the NtlmAuthenticator.
Determine whether or not the "default credentials" (e.g. the user account under which the current process is
running) will be sent along to the server. The default is false.
Set to true if you need the Content-Type not to have the charset
X509CertificateCollection to be sent with request
Flag to send authorisation header with the HttpWebRequest
Modifies the default behavior of RestSharp to swallow exceptions.
When set to true
, a will be thrown
in case RestSharp fails to deserialize the response.
Modifies the default behavior of RestSharp to swallow exceptions.
When set to true
, RestSharp will consider the request as unsuccessful
in case it fails to deserialize the response.
Modifies the default behavior of RestSharp to swallow exceptions.
When set to true
, exceptions will be re-thrown.
Callback function for handling the validation of remote certificates. Useful for certificate pinning and
overriding certificate errors in the scope of a request.
By default, RestSharp doesn't allow multiple parameters to have the same name.
This properly allows to override the default behavior.
Use System.Text.Json serializer with default settings
Use System.Text.Json serializer with custom settings
System.Text.Json serializer options
Create the new serializer that uses System.Text.Json.JsonSerializer with default settings
Create the new serializer that uses System.Text.Json.JsonSerializer with custom settings
Json serializer settings
Wrapper for System.Xml.Serialization.XmlSerializer.
Encoding for serialized content
Name of the root element to use when serializing
XML namespace to use when serializing
Wrapper for System.Xml.Serialization.XmlSerializer.
Default constructor, does not specify namespace
Specify the namespaced to be used when serializing
XML namespace
Encoding for serialized content
Serialize the object as XML
Object to serialize
XML as string
Name of the root element to use when serializing
XML namespace to use when serializing
Format string to use when serializing dates
Content type for serialized content
Reserved to be used by the compiler for tracking metadata.
This class should not be used by developers in source code.
This definition is provided by the IsExternalInit NuGet package (https://www.nuget.org/packages/IsExternalInit).
Please see https://github.com/manuelroemer/IsExternalInit for more information.