C# Class PortableRest.RestRequest

Specifies the parameters for the HTTP request that will be executed against a given resource.
Show file Open project: advancedrei/PortableRest Class Usage Examples

Private Properties

Property Type Description
CombineUriParts string
GetContentType string
GetRequestBody string
Transform void

Public Methods

Method Description
AddFileParameter ( string key, System.Stream fileStream, string filename ) : void

AddHeader ( string key, object value ) : void

Adds an Header to only this specific request.

Use this if you have an authentication token that times out on a regular basis.

AddParameter ( object value ) : void

Adds an unnamed parameter to the body of the request.

Use this method if you're not using UrlFormEncoded requests.

AddParameter ( string key, object value, ParameterEncoding encoding = ParameterEncoding.UriEncoded ) : void

Adds a parameter to the body of the request, to be encoded with the specified format.

Note: If the ContentType is anything other than UrlFormEncoded, only the first Parameter will be serialzed to the request body.

AddQueryString ( string key, object value ) : void

Appends a key/value pair to the end of the existing QueryString in a URI.

AddQueryString ( string key, string value ) : void

Appends a key/value pair to the end of the existing QueryString in a URI.

AddUrlSegment ( string key, string value ) : void

Replaces tokenized segments of the URL with a desired value.

GetResourceUri ( string baseUrl ) : Uri

RestRequest ( ) : System

Creates a new RestRequest instance, assuming the request will be an HTTP GET.

RestRequest ( string resource ) : System

Creates a new RestRequest instance for a given Resource.

RestRequest ( string resource, ContentTypes contentType ) : System

Creates a new RestRequest instance for a given Resource and Method, specifying whether or not to ignore the root object in the response.

RestRequest ( string resource, HttpMethod method ) : System

Creates a new RestRequest instance for a given Resource and Method.

RestRequest ( string resource, HttpMethod method, ContentTypes contentType ) : System

Creates a new RestRequest instance for a given Resource and Method, specifying whether or not to ignore the root object in the response.

RestRequest ( string resource, HttpMethod method, bool ignoreRoot ) : System

Creates a new RestRequest instance for a given Resource and Method, specifying whether or not to ignore the root object in the response.

Private Methods

Method Description
CombineUriParts ( ) : string

Combines URI parts, taking care of trailing and starting slashes. See http://stackoverflow.com/a/6704287

GetContentType ( ) : string

GetRequestBody ( ) : string

Transform ( XNode node, Type type ) : void

Technique from http://blogs.msdn.com/b/ericwhite/archive/2009/07/20/a-tutorial-in-the-recursive-approach-to-pure-functional-transformations-of-xml.aspx

Method Details

AddFileParameter() public method

public AddFileParameter ( string key, System.Stream fileStream, string filename ) : void
key string
fileStream System.Stream
filename string
return void

AddHeader() public method

Adds an Header to only this specific request.
Use this if you have an authentication token that times out on a regular basis.
public AddHeader ( string key, object value ) : void
key string
value object
return void

AddParameter() public method

Adds an unnamed parameter to the body of the request.
Use this method if you're not using UrlFormEncoded requests.
public AddParameter ( object value ) : void
value object
return void

AddParameter() public method

Adds a parameter to the body of the request, to be encoded with the specified format.
Note: If the ContentType is anything other than UrlFormEncoded, only the first Parameter will be serialzed to the request body.
public AddParameter ( string key, object value, ParameterEncoding encoding = ParameterEncoding.UriEncoded ) : void
key string
value object /// For ByteArrays or Base64, this needs to be a Stream, or an exception will be thrown when the request is executed. ///
encoding ParameterEncoding
return void

AddQueryString() public method

Appends a key/value pair to the end of the existing QueryString in a URI.
public AddQueryString ( string key, object value ) : void
key string The string key to append to the QueryString.
value object The value to append to the QueryString (we will call .ToString() for you).
return void

AddQueryString() public method

Appends a key/value pair to the end of the existing QueryString in a URI.
public AddQueryString ( string key, string value ) : void
key string The string key to append to the QueryString.
value string The string value to append to the QueryString.
return void

AddUrlSegment() public method

Replaces tokenized segments of the URL with a desired value.
public AddUrlSegment ( string key, string value ) : void
key string
value string
return void

GetResourceUri() public method

public GetResourceUri ( string baseUrl ) : Uri
baseUrl string
return System.Uri

RestRequest() public method

Creates a new RestRequest instance, assuming the request will be an HTTP GET.
public RestRequest ( ) : System
return System

RestRequest() public method

Creates a new RestRequest instance for a given Resource.
public RestRequest ( string resource ) : System
resource string The specific resource to access.
return System

RestRequest() public method

Creates a new RestRequest instance for a given Resource and Method, specifying whether or not to ignore the root object in the response.
public RestRequest ( string resource, ContentTypes contentType ) : System
resource string The URL format string of the resource to request.
contentType ContentTypes The Content Type for the request.
return System

RestRequest() public method

Creates a new RestRequest instance for a given Resource and Method.
public RestRequest ( string resource, HttpMethod method ) : System
resource string The specific resource to access.
method HttpMethod The HTTP method to use for the request.
return System

RestRequest() public method

Creates a new RestRequest instance for a given Resource and Method, specifying whether or not to ignore the root object in the response.
public RestRequest ( string resource, HttpMethod method, ContentTypes contentType ) : System
resource string The URL format string of the resource to request.
method HttpMethod The for the request.
contentType ContentTypes The Content Type for the request.
return System

RestRequest() public method

Creates a new RestRequest instance for a given Resource and Method, specifying whether or not to ignore the root object in the response.
public RestRequest ( string resource, HttpMethod method, bool ignoreRoot ) : System
resource string The URL format string of the resource to request.
method HttpMethod The for the request.
ignoreRoot bool Whether or not the root object from the response should be ignored.
return System