RestSharp
JSON WEB TOKEN (JWT) Authenticator class.
https://tools.ietf.org/html/draft-ietf-oauth-json-web-token
Tries to Authenticate with the credentials of the currently logged in user, or impersonate a user
Authenticate with the credentials of the currently logged in user
Authenticate by impersonation
Authenticate by impersonation, using an existing ICredentials instance
Base class for OAuth 2 Authenticators.
Since there are many ways to authenticate in OAuth2,
this is used as a base class to differentiate between
other authenticators.
Any other OAuth2 authenticators must derive from this
abstract class.
Access token to be used when authenticating.
Initializes a new instance of the class.
The access token.
Gets the access token.
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.
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
Stores the Authorization header value as "[tokenType] accessToken". used for performance.
Initializes a new instance of the class.
The access token.
Initializes a new instance of the class.
The access token.
The token type.
All text parameters are UTF-8 encoded (per section 5.1).
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 signature base
The consumer secret
The token secret
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 a instance to pass to an
for the purpose of requesting an
unauthorized request token.
The HTTP method for the intended request
Generates a instance 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 a instance to pass to an
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
Generates a instance to pass to an
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 a instance 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
Types of parameters that can be added to requests
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!
Save a byte array to a file
Bytes to save
Full path to save file to
Read a stream into a byte array
Stream to read
byte[]
Copies bytes from one stream to another
The input stream.
The output stream.
Converts a byte array to a string, using its byte order mark to convert it to the right encoding.
http://www.shrinkrays.net/code-snippets/csharp/an-extension-method-for-converting-a-byte-array-to-a-string.aspx
An array of bytes to convert
Content encoding. Will fallback to UTF8 if not a valid encoding.
The byte as a string.
Converts a byte array to a string, using its byte order mark to convert it to the right encoding.
http://www.shrinkrays.net/code-snippets/csharp/an-extension-method-for-converting-a-byte-array-to-a-string.aspx
An array of bytes to convert
The byte as a string using UTF8.
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
Convert a to a instance.
The response status.
responseStatus
Imports the specified XML String into the crypto service provider
.NET Core 2.0 doesn't provide an implementation of RSACryptoServiceProvider.FromXmlString/ToXmlString, so we have to do it ourselves.
Source: https://gist.github.com/Jargon64/5b172c452827e15b21882f1d76a94be4/
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
Check that a string is not null or empty
String to check
bool
Remove underscores from a string
String to process
string
Parses most common JSON date formats
JSON value to parse
DateTime
Remove leading and trailing " from a string
String to parse
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
Convert the first letter of a string to lower case
String to convert
string
Checks to see if a string is all uppper case
String to check
bool
Add underscores to a pascal-cased string
String to convert
string
Add dashes to a pascal-cased string
String to convert
string
Add an undescore prefix to a pascasl-cased string
Add spaces to a pascal-cased string
String to convert
string
Return possible variants of a name for name matching.
String to convert
The culture to use for conversion
IEnumerable<string>
XML Extension Methods
Returns the name of an element with the namespace if specified
Element name
XML Namespace
Container for files to be uploaded with requests
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.
The data to use as the file's contents.
The filename to use in the request.
The using the default content type.
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 length of the data that will be written by te writer.
The filename to use in the request.
Optional: parameter content type
The using the default content type.
The length of data to be sent
Provides raw data for file
Name of the file to use when uploading
MIME content type of file
Name of the parameter
HttpWebRequest wrapper (async methods)
HttpWebRequest wrapper
HttpWebRequest wrapper (sync methods)
Execute an async POST-style request with the specified HTTP Method.
The HTTP method to execute.
Execute an async GET-style request with the specified HTTP Method.
The HTTP method to execute.
Default constructor
True if this HTTP request has any HTTP parameters
True if this HTTP request has any HTTP cookies
True if a request body has been specified
True if files have been set to be uploaded
Enable or disable automatic gzip/deflate decompression
Always send a multipart/form-data request - even when no Files are present.
UserAgent to be sent with request
Timeout in milliseconds to be used for the request
The number of milliseconds before the writing or reading times out.
System.Net.ICredentials to be sent with request
The System.Net.CookieContainer to be used for the request
The delegate to use to write the response instead of reading into RawBytes
Here you can also check the request details
The delegate to use to write the response instead of reading into RawBytes
Collection of files to be sent with request
Whether or not HTTP 3xx response redirects should be automatically followed
Whether or not to use pipelined connections
X509CertificateCollection to be sent with request
Maximum number of automatic redirects to follow if FollowRedirects is true
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 ConnectionGroupName property enables you to associate a request with a connection group.
Encoding for the request, UTF8 is the default
HTTP headers to be sent with request
HTTP parameters (QueryString or Form values) to be sent with request
HTTP cookies to be sent with request
Request body to be sent with request
Content type of the request body.
An alternative to RequestBody, for when the caller already has the byte array.
URL to call for this request
Explicit Host header value to use in requests independent from the request URI.
If null, default host value extracted from URI is used.
List of Allowed Decompression Methods
Flag to send authorisation header with the HttpWebRequest
Flag to reuse same connection in the HttpWebRequest
Proxy info to be sent with request
Caching policy for requests created with this wrapper.
Callback function for handling the validation of remote certificates.
Creates an IHttp
Execute a POST request
Execute a PUT request
Execute a GET request
Execute a HEAD request
Execute an OPTIONS request
Execute a DELETE request
Execute a PATCH request
Execute a MERGE request
Execute a GET-style request with the specified HTTP Method.
The HTTP method to execute.
Execute a POST-style request with the specified HTTP Method.
The HTTP method to execute.
Representation of an HTTP cookie
Comment of the cookie
Comment of the cookie
Indicates whether the cookie should be discarded at the end of the session
Domain of the cookie
Indicates whether the cookie is expired
Date and time that the cookie expires
Indicates that this cookie should only be accessed by the server
Name of the cookie
Path of the cookie
Port of the cookie
Indicates that the cookie should only be sent over secure channels
Date and time the cookie was created
Value of the cookie
Version of the cookie
Container for HTTP file
The length of data to be sent
Provides raw data for file
Name of the file to use when uploading
MIME content type of file
Name of the parameter
Representation of an HTTP header
Name of the header
Value of the header
Representation of an HTTP parameter (QueryString or Form value)
Name of the parameter
Value of the parameter
Content-Type of the parameter
HTTP response data
Default constructor
MIME content type of response
Length in bytes of the response content
Encoding of the response content
Lazy-loaded string representation of response content
HTTP response status code
Description of HTTP status returned
Response content
The URL that actually responded to the content (different from request if redirected)
HttpWebResponse.Server
Headers returned by server with the response
Cookies 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
Exception thrown when error is encountered.
The HTTP protocol version (1.0, 1.1, etc)
Only set when underlying framework supports it.
Enable or disable automatic gzip/deflate decompression
Always send a multipart/form-data request - even when no Files are present.
An alternative to RequestBody, for when the caller already has the byte array.
HTTP response data
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
Description of HTTP status returned
Response content
The URL that actually responded to the content (different from request if redirected)
HttpWebResponse.Server
Headers returned by server with the response
Cookies 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
Exception thrown when error is encountered.
The HTTP protocol version (1.0, 1.1, etc)
Only set when underlying framework supports it.
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));
X509CertificateCollection to be sent with request
Callback function for handling the validation of remote certificates. Useful for certificate pinning and
overriding certificate errors in the scope of a request.
Executes a GET-style request and callback asynchronously, authenticating if needed
Request to be executed
Callback function to be executed upon completion providing access to the async handle.
The HTTP method to execute
Executes a POST-style request and callback asynchronously, authenticating if needed
Request to be executed
Callback function to be executed upon completion providing access to the async handle.
The HTTP method to execute
Executes a GET-style request and callback asynchronously, authenticating if needed
Target deserialization type
Request to be executed
Callback function to be executed upon completion
The HTTP method to execute
Executes a GET-style request and callback asynchronously, authenticating if needed
Target deserialization type
Request to be executed
Callback function to be executed upon completion
The HTTP method to execute
Add a delegate to apply custom configuration to HttpWebRequest before making a call
Configuration delegate for HttpWebRequest
Adds or replaces a deserializer for the specified content type
Content type for which the deserializer will be replaced
Custom deserializer
Adds or replaces a deserializer for the specified content type
Content type for which the deserializer will be replaced
Custom deserializer factory
Removes custom deserialzier for the specified content type
Content type for which deserializer needs to be removed
Remove deserializers for all content types
Executes the request and callback asynchronously, authenticating if needed
Target deserialization type
Request to be executed
The cancellation token
Executes the request asynchronously, authenticating if needed
Target deserialization type
Request to be executed
Override the request method
Executes the request asynchronously, authenticating if needed
Target deserialization type
Request to be executed
Executes a GET-style request asynchronously, authenticating if needed
Target deserialization type
Request to be executed
Executes a GET-style request asynchronously, authenticating if needed
Target deserialization type
Request to be executed
The cancellation token
Executes a POST-style request asynchronously, authenticating if needed
Target deserialization type
Request to be executed
Executes a POST-style request asynchronously, authenticating if needed
Target deserialization type
Request to be executed
The cancellation token
Executes the request and callback asynchronously, authenticating if needed
Request to be executed
The cancellation token
Executes the request and callback asynchronously, authenticating if needed
Request to be executed
The cancellation token
Override the request method
Executes the request asynchronously, authenticating if needed
Request to be executed
Executes a GET-style asynchronously, authenticating if needed
Request to be executed
Executes a GET-style asynchronously, authenticating if needed
Request to be executed
The cancellation token
Executes a POST-style asynchronously, authenticating if needed
Request to be executed
Executes a POST-style asynchronously, authenticating if needed
Request to be executed
The cancellation token
Always send a multipart/form-data request - even when no Files are present.
Serializer to use when writing JSON request bodies. Used if RequestFormat is Json.
By default the included JsonSerializer is used (currently using SimpleJson default serialization).
Serializer to use when writing XML request bodies. Used if RequestFormat is Xml.
By default the included XmlSerializer is used.
Set this to handle the response stream yourself, based on the response details
Set this to write response to Stream rather than reading into memory.
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
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 XML request bodies. Used if RequestFormat is Xml.
By default XmlSerializer is used.
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.
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.
In general you would not need to set this directly. Used by the NtlmAuthenticator.
Timeout in milliseconds to be used for the request. This timeout value overrides a timeout set on the RestClient.
The number of milliseconds before the writing or reading times out. This timeout value overrides a timeout set on the RestClient.
How many attempts were made to send this Request?
This Number is incremented each time the RestClient sends the request.
Useful when using Asynchronous Execution with Callbacks
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.
List of Allowed Decompression Methods
Adds a file to the Files collection to be included with a POST or PUT request
(other methods do not support file uploads).
The parameter name to use in the request
Full path to file to upload
The MIME type of the file to upload
This request
Adds the bytes to the Files collection with the specified file name and content type
The parameter name to use in the request
The file data
The file name to use for the uploaded file
The MIME type of the file to upload
This request
Adds the bytes to the Files collection with the specified file name and content type
The parameter name to use in the request
A function that writes directly to the stream. Should NOT close the stream.
The file name to use for the uploaded file
The length (in bytes) of the file content.
The MIME type of the file to upload
This request
Add bytes to the Files collection as if it was a file of specific type
A form parameter name
The file data
The file name to use for the uploaded file
Specific content type. Es: application/x-gzip
Serializes obj to format specified by RequestFormat, but passes xmlNamespace if using the default XmlSerializer
The default format is XML. Change RequestFormat if you wish to use a different serialization format.
The object to serialize
The XML namespace to use when serializing
This request
Serializes obj to data format specified by RequestFormat and adds it to the request body.
The default format is XML. Change RequestFormat if you wish to use a different serialization format.
The object to serialize
This request
Serializes obj to JSON format and adds it to the request body.
The object to serialize
This request
Serializes obj to XML format and adds it to the request body.
The object to serialize
This request
Serializes obj to format specified by RequestFormat, but passes xmlNamespace if using the default XmlSerializer
Serializes obj to XML format and passes xmlNamespace then adds it to the request body.
The object to serialize
The XML namespace to use when serializing
This request
Calls AddParameter() for all public, readable properties specified in the includedProperties list
request.AddObject(product, "ProductId", "Price", ...);
The object with properties to add as parameters
The names of the properties to include
This request
Calls AddParameter() for all public, readable properties of obj
The object with properties to add as parameters
This request
Add the parameter to the request
Parameter to add
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
This request
Adds a parameter to the request. There are five 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}
- Cookie: Adds the name/value pair to the HTTP request's Cookies collection
- RequestBody: Used by AddBody() (not recommended to use directly)
Name of the parameter
Value of the parameter
The type of parameter to add
This request
Adds a parameter to the request. There are five 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}
- Cookie: Adds the name/value pair to the HTTP request's Cookies collection
- RequestBody: Used by AddBody() (not recommended to use directly)
Name of the parameter
Value of the parameter
Content-Type of the parameter
The type of parameter to add
This request
Add or update the parameter to the request
Parameter to add
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
This request
Adds a parameter to the request. There are five 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}
- Cookie: Adds the name/value pair to the HTTP request's Cookies collection
- RequestBody: Used by AddBody() (not recommended to use directly)
Name of the parameter
Value of the parameter
The type of parameter to add
This request
Adds a parameter to the request. There are five 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}
- Cookie: Adds the name/value pair to the HTTP request's Cookies collection
- RequestBody: Used by AddBody() (not recommended to use directly)
Name of the parameter
Value of the parameter
Content-Type of the parameter
The type of parameter to add
This request
Shortcut to AddParameter(name, value, HttpHeader) overload
Name of the header to add
Value of the header to add
Shortcut to AddParameter(name, value, Cookie) overload
Name of the cookie to add
Value of the cookie to add
Shortcut to AddParameter(name, value, UrlSegment) overload
Name of the segment to add
Value of the segment to add
Shortcut to AddParameter(name, value, QueryString) overload
Name of the parameter to add
Value of the parameter to add
Shortcut to AddParameter(name, value, QueryString) overload
Name of the parameter to add
Value of the parameter to add
Whether parameter should be encoded or not
Container for data sent back from API
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
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
Exceptions thrown during the request, if any.
Will contain only network transport or framework exceptions thrown during the request.
HTTP protocol errors are handled by RestSharp and will not appear here.
The HTTP protocol version (1.0, 1.1, etc)
Only set when underlying framework supports it.
Container for data sent back from API including deserialized data
Type of data to deserialize to
Deserialized entity data
Parameter container for REST requests
Name of the parameter
Value of the parameter
Type of the parameter
Body parameter data type
MIME content type of the parameter
Return a human-readable representation of this parameter
String
Client to translate RestRequests into Http requests and process response result
Executes the request and callback asynchronously, authenticating if needed
Request to be executed
Callback function to be executed upon completion providing access to the async handle.
HTTP call method (GET, PUT, etc)
Executes the request and callback asynchronously, authenticating if needed
Request to be executed
Callback function to be executed upon completion providing access to the async handle.
Executes a GET-style request and callback asynchronously, authenticating if needed
Request to be executed
Callback function to be executed upon completion providing access to the async handle.
The HTTP method to execute
Executes a POST-style request and callback asynchronously, authenticating if needed
Request to be executed
Callback function to be executed upon completion providing access to the async handle.
The HTTP method to execute
Executes the request and callback asynchronously, authenticating if needed
Target deserialization type
Request to be executed
Callback function to be executed upon completion
Override the request http method
Executes the request and callback asynchronously, authenticating if needed
Target deserialization type
Request to be executed
Callback function to be executed upon completion
Executes a GET-style request and callback asynchronously, authenticating if needed
Target deserialization type
Request to be executed
Callback function to be executed upon completion
The HTTP method to execute
Executes a POST-style request and callback asynchronously, authenticating if needed
Target deserialization type
Request to be executed
Callback function to be executed upon completion
The HTTP method to execute
Executes a GET-style request asynchronously, authenticating if needed
Target deserialization type
Request to be executed
Executes a GET-style request asynchronously, authenticating if needed
Target deserialization type
Request to be executed
The cancellation token
Executes a POST-style request asynchronously, authenticating if needed
Target deserialization type
Request to be executed
Executes a POST-style request asynchronously, authenticating if needed
Target deserialization type
Request to be executed
The cancellation token
Executes the request asynchronously, authenticating if needed
Target deserialization type
Request to be executed
Override the request method
Executes the request asynchronously, authenticating if needed
Target deserialization type
Request to be executed
Executes the request asynchronously, authenticating if needed
Target deserialization type
Request to be executed
The cancellation token
Override the request method
Executes the request asynchronously, authenticating if needed
Target deserialization type
Request to be executed
The cancellation token
Executes the request asynchronously, authenticating if needed
Request to be executed
Executes a GET-style asynchronously, authenticating if needed
Request to be executed
Executes a GET-style asynchronously, authenticating if needed
Request to be executed
The cancellation token
Executes a POST-style asynchronously, authenticating if needed
Request to be executed
Executes a POST-style asynchronously, authenticating if needed
Request to be executed
The cancellation token
Executes the request asynchronously, authenticating if needed
Request to be executed
The cancellation token
Override the request method
Executes the request asynchronously, authenticating if needed
Request to be executed
The cancellation token
Default constructor that registers default content handlers
Sets the BaseUrl property for requests made by this client instance
Sets the BaseUrl property for requests made by this client instance
Replace the default serializer with a custom one
The custom serializer instance
Replace the default serializer with a custom one
A function that creates a custom serializer instance
Replace the default serializer with a custom one
The type that implements IRestSerializer
Allows to use a custom way to encode parameters
A delegate to encode parameters
client.UseUrlEncoder(s => HttpUtility.UrlEncode(s));
Enable or disable automatic gzip/deflate decompression
Maximum number of redirects to follow if FollowRedirects is true
X509CertificateCollection to be sent with request
Proxy to use for requests made by this client instance.
Passed on to underlying WebRequest if set.
The cache policy to use for requests initiated by this client instance.
Default is true. Determine whether or not requests that result in
HTTP status codes of 3xx should follow returned redirect
The CookieContainer used for requests made by this client instance
UserAgent to use for requests made by this client instance
Timeout in milliseconds to use for requests made by this client instance.
If not set, the default timeout for HttpWebRequest is used.
The number of milliseconds before the writing or reading times out.
Whether to invoke async callbacks using the SynchronizationContext.Current captured when invoked
Authenticator to use for requests made by this client instance
Combined with Request.Resource to construct URL for request
Should include scheme and domain without trailing slash.
client.BaseUrl = new Uri("http://example.com");
Set to false if you want to get ResponseStatus.Completed when deserialization fails.
Default is true.
Allow high-speed NTLM-authenticated connection sharing
The ConnectionGroupName property enables you to associate a request with a connection group.
Callback function for handling the validation of remote certificates. Useful for certificate pinning and
overriding certificate errors in the scope of a request.
Parameters included with every request made with this instance of RestClient
If specified in both client and request, the request wins
Explicit Host header value to use in requests independent from the request URI.
If null, default host value extracted from URI is used.
Set to true if you need to add multiple default parameters with the same name.
Only query and form parameters are supported.
Registers a content handler to process response content
MIME content type of the response content
Deserializer to use to process content
Registers a content handler to process response content
MIME content type of the response content
Deserializer to use to process content
Registers a content handler to process response content
A list of MIME content types of the response content
Deserializer factory to use to process content
Registers a content handler to process response content
A list of MIME content types of the response content
Deserializer to use to process content
Remove a content handler for the specified MIME content type
MIME content type to remove
Remove all content handlers
Assembles URL to call based on parameters, method and resource
RestRequest to execute
Assembled System.Uri
Executes the specified request and downloads the response data
Request to execute
Response data
Executes the specified request and downloads the response data
Request to execute
Throw an exception if download fails.
Response data
Executes the request and returns a response, authenticating if needed
Request to be executed
Override the http method in the request
RestResponse
Executes the request and returns a response, authenticating if needed
Request to be executed
RestResponse
Executes the specified request and deserializes the response content using the appropriate content handler
Target deserialization type
Request to execute
RestResponse[[T]] with deserialized data in Data property
Executes the request and callback asynchronously, authenticating if needed
The IRestClient this method extends
Request to be executed
Callback function to be executed upon completion
Executes the request and callback asynchronously, authenticating if needed
The IRestClient this method extends
Target deserialization type
Request to be executed
Callback function to be executed upon completion providing access to the async handle
Execute the request using GET HTTP method. Exception will be thrown if the request does not succeed.
RestClient instance
The request
Expected result type
Execute the request using POST HTTP method. Exception will be thrown if the request does not succeed.
RestClient instance
The request
Expected result type
Execute the request using PUT HTTP method. Exception will be thrown if the request does not succeed.
RestClient instance
The request
Expected result type
Execute the request using HEAD HTTP method. Exception will be thrown if the request does not succeed.
RestClient instance
The request
Expected result type
Execute the request using OPTIONS HTTP method. Exception will be thrown if the request does not succeed.
RestClient instance
The request
Expected result type
Execute the request using PATCH HTTP method. Exception will be thrown if the request does not succeed.
RestClient instance
The request
Expected result type
Execute the request using DELETE HTTP method. Exception will be thrown if the request does not succeed.
RestClient instance
The request
Expected result type
Add a parameter to use on every request made with this client instance
The IRestClient instance
Parameter to add
Removes a parameter from the default parameters that are used on every request made with this client instance
The IRestClient instance
The name of the parameter that needs to be removed
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
The IRestClient instance
Name of the parameter
Value of the parameter
This request
Adds a default parameter to the request. 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
The IRestClient 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.
The IRestClient instance
Name of the header to add
Value of the header to add
Adds a default URL segment parameter to the RestClient. Used on every request made by this client instance.
The IRestClient 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.
The IRestClient instance
Name of the query parameter to add
Value of the query parameter to add
Container for data used to make requests
Local list of Allowed Decompression Methods
Default constructor
Sets Method property to value of method
Method to use for this request
Gets or sets a user-defined state object that contains information about a request and which can be later
retrieved when the request completes.
List of Allowed Decompresison Methods
Always send a multipart/form-data request - even when no Files are present.
Serializer to use when writing JSON request bodies. Used if RequestFormat is Json.
By default the included JsonSerializer is used (currently using JSON.NET default serialization).
Serializer to use when writing XML request bodies. Used if RequestFormat is Xml.
By default the included XmlSerializer is used.
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
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.
Adds a file to the Files collection to be included with a POST or PUT request
(other methods do not support file uploads).
The parameter name to use in the request
Full path to file to upload
The MIME type of the file to upload
This request
Adds the bytes to the Files collection with the specified file name
The parameter name to use in the request
The file data
The file name to use for the uploaded file
The MIME type of the file to upload
This request
Adds the bytes to the Files collection with the specified file name and content type
The parameter name to use in the request
A function that writes directly to the stream. Should NOT close the stream.
The file name to use for the uploaded file
The length (in bytes) of the file content.
The MIME type of the file to upload
This request
Add bytes to the Files collection as if it was a file of specific type
A form parameter name
The file data
The file name to use for the uploaded file
Specific content type. Es: application/x-gzip
Serializes obj to format specified by RequestFormat, but passes xmlNamespace if using the default XmlSerializer
The default format is XML. Change RequestFormat if you wish to use a different serialization format.
The object to serialize
The XML namespace to use when serializing
This request
Serializes obj to data format specified by RequestFormat and adds it to the request body.
The default format is XML. Change RequestFormat if you wish to use a different serialization format.
The object to serialize
This request
Serializes obj to JSON format and adds it to the request body.
The object to serialize
This request
Serializes obj to XML format and adds it to the request body.
The object to serialize
This request
Serializes obj to XML format and passes xmlNamespace then adds it to the request body.
The object to serialize
The XML namespace to use when serializing
This request
Calls AddParameter() for all public, readable properties specified in the includedProperties list
request.AddObject(product, "ProductId", "Price", ...);
The object with properties to add as parameters
The names of the properties to include
This request
Calls AddParameter() for all public, readable properties of obj
The object with properties to add as parameters
This request
Add the parameter to the request
Parameter to add
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
This request
Adds a parameter to the request. 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)
Name of the parameter
Value of the parameter
The type of parameter to add
This request
Adds a parameter to the request. 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)
Name of the parameter
Value of the parameter
Content-Type of the parameter
The type of parameter to add
This request
Adds a parameter to the request or updates it with the given argument, if the parameter already exists in the
request
Parameter to add
Adds a HTTP parameter to the request or updates it with the given argument, if the parameter already exists in the
request
(QueryString for GET, DELETE, OPTIONS and HEAD; Encoded form for POST and PUT)
Name of the parameter
Value of the parameter
This request
Adds a HTTP parameter to the request or updates it with the given argument, if the parameter already exists in the
request
- 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)
Name of the parameter
Value of the parameter
The type of parameter to add
This request
Adds a HTTP parameter to the request or updates it with the given argument, if the parameter already exists in the
request
- 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)
Name of the parameter
Value of the parameter
Content-Type of the parameter
The type of parameter to add
This request
Shortcut to AddParameter(name, value, HttpHeader) overload
Name of the header to add
Value of the header to add
Shortcut to AddParameter(name, value, Cookie) overload
Name of the cookie to add
Value of the cookie to add
Shortcut to AddParameter(name, value, UrlSegment) overload
Name of the segment to add
Value of the segment to add
Shortcut to AddParameter(name, value, QueryString) overload
Name of the parameter to add
Value of the parameter to add
Shortcut to AddParameter(name, value, QueryString) overload
Name of the parameter to add
Value of the parameter to add
Whether parameter should be encoded or not
Add a Decompression Method to the request
None | GZip | Deflate
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
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);
Determines how to serialize the request body.
By default Xml is used.
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.
A function to run prior to deserializing starting (e.g. change settings if error encountered)
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.
In general you would not need to set this directly. Used by the NtlmAuthenticator.
Timeout in milliseconds to be used for the request. This timeout value overrides a timeout set on the RestClient.
The number of milliseconds before the writing or reading times out. This timeout value overrides a timeout set on
the RestClient.
Internal Method so that RestClient can increase the number of attempts
How many attempts were made to send this Request?
This Number is incremented each time the RestClient sends the request.
Useful when using Asynchronous Execution with Callbacks
Shortcut to AddParameter(name, value, UrlSegment) overload
Name of the segment to add
Value of the segment to add
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
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
The HTTP protocol version (1.0, 1.1, etc)
Only set when underlying framework supports it.
Assists with debugging responses by displaying in the debugger output
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
Comment of the cookie
Comment of the cookie
Indicates whether the cookie should be discarded at the end of the session
Domain of the cookie
Indicates whether the cookie is expired
Date and time that the cookie expires
Indicates that this cookie should only be accessed by the server
Name of the cookie
Path of the cookie
Port of the cookie
Indicates that the cookie should only be sent over secure channels
Date and time the cookie was created
Value of the cookie
Version of the cookie
Serialize the object as JSON
If the object is already a serialized string returns it's value
Object to serialize
JSON as String
Determines if the object is already a serialized string.
Content type for serialized content
Name of the root element to use when serializing
XML namespace to use when serializing
Format string to use when serializing dates
Allows control how class and property names and values are deserialized by XmlAttributeDeserializer
The name to use for the serialized element
Sets if the property to Deserialize is an Attribute or Element (Default: false)
Sets if the property to Deserialize is a content of current Element (Default: false)
Wrapper for System.Xml.Serialization.XmlSerializer.
Name of the root element to use when serializing
XML namespace to use when serializing
Encoding for serialized content
Allows control how class and property names and values are serialized by XmlSerializer
Currently not supported with the JsonSerializer
When specified at the property level the class-level specification is overridden
The name to use for the serialized element
Sets the value to be serialized as an Attribute instead of an Element
Sets the value to be serialized as text content of current Element instead of an new Element
The culture to use when serializing
Transforms the casing of the name based on the selected value.
The order to serialize the element. Default is int.MaxValue.
Called by the attribute when NameStyle is speficied
The string to transform
String
Options for transforming casing of element names
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
Default XML Serializer
Default constructor, does not specify namespace
Specify the namespaced to be used when serializing
XML namespace
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
Determines if a given object is numeric in any way
(can be integer, double, null, etc).
Represents the json array.
Initializes a new instance of the class.
Initializes a new instance of the class.
The capacity of the json array.
The json representation of the array.
The json representation of the array.
Represents the json object.
The internal member dictionary.
Initializes a new instance of .
Initializes a new instance of .
The implementation to use when comparing keys, or null to use the default for the type of the key.
Gets the at the specified index.
Adds the specified key.
The key.
The value.
Determines whether the specified key contains key.
The key.
true if the specified key contains key; otherwise, false.
Gets the keys.
The keys.
Removes the specified key.
The key.
Tries the get value.
The key.
The value.
Gets the values.
The values.
Gets or sets the with the specified key.
Adds the specified item.
The item.
Clears this instance.
Determines whether [contains] [the specified item].
The item.
true if [contains] [the specified item]; otherwise, false.
Copies to.
The array.
Index of the array.
Gets the count.
The count.
Gets a value indicating whether this instance is read only.
true if this instance is read only; otherwise, false.
Removes the specified item.
The item.
Gets the enumerator.
Returns an enumerator that iterates through a collection.
An object that can be used to iterate through the collection.
Returns a json that represents the current .
A json that represents the current .
This class encodes and decodes JSON strings.
Spec. details, see http://www.json.org/
JSON uses Arrays and Objects. These correspond here to the datatypes JsonArray(IList<object>) and JsonObject(IDictionary<string,object>).
All numbers are parsed to doubles.
Parses the string json into a value
A JSON string.
An IList<object>, a IDictionary<string,object>, a double, a string, null, true, or false
Try parsing the json string into a value.
A JSON string.
The object.
Returns true if successfull otherwise false.
Converts a IDictionary<string,object> / IList<object> object into a JSON string
A IDictionary<string,object> / IList<object>
Serializer strategy to use
A JSON encoded string, or null if object 'json' is not serializable
Determines if a given object is numeric in any way
(can be integer, double, null, etc).
Helper methods for validating required values
Require a parameter to not be null
Name of the parameter
Value of the parameter
Helper methods for validating values
Validate an integer value is between the specified values (exclusive of min/max)
Value to validate
Exclusive minimum value
Exclusive maximum value
Validate a string length
String to be validated
Maximum length of the string