Skip to content

RestRequest

Scott Offen edited this page Nov 12, 2014 · 6 revisions

Grapevine.Client.RESTRequest

Contains all data required to send a request to a RESTClient, including the pattern for the resource, the request method and the request payload content type.

Constructor

RESTRequest has a named and optional argument constructor. All arguments are optional.

Argument Type Default
resource string empty
method HttpMethod HttpMethod.GET
type ContentType ContentType.TXT
timeout int RESTRequest.GlobalTimeout
encoding Encoding Encoding.UTF8

See the Properties section below for more information.

Methods

AddParameter (String name, String value)

A name/value pair should be added for every token in the resource string, where the name is the same as the string inside the curly braces.

var r = new RESTRequest("/person/{id}");
r.AddParameter("id", "1234");
Console.WriteLine(r.PathInfo);
// > /person/1234
  • When the Reset method is called, all parameters are cleared.

AddQuery (string name, string value)

These name/value pairs will be joined into a query string when the QueryString property is requested.

var r = new RESTRequest("/person/search");
r.AddQuery("gender", "male");
r.AddQuery("age", "93");
Console.WriteLine(r.QueryString);
// > gender=male&age=93
  • You should not URI-encode the names or the values.
  • Returns null if there are no key/value pairs.
  • When the Reset method is called, all query string values are cleared.

Reset ()

The Reset method clears the Payload property and clears all provided parameters and query string key-value pairs. This method is called by default whenever a request is executed, regardless of the response returned.

Properties

ContentType : ContentType

Gets or sets the ContentType to be used for this request.

Encoding : Encoding

Gets or sets the Encoding to be used for this request.

Get and/or otherwise interact with the WebHeaderCollection for this client. All headers are sent with each request. Headers are not cleared when Reset is called.

Method : HttpMethod

Gets or sets the HttpMethod to be used for this request.

PathInfo : String

Returns the Resource string with all tokens replaced by their respective values added via the AddParameters method.

var r = new RESTRequest("/person/{id}");
r.AddParameter("id", "1234");
Console.WriteLine(r.PathInfo);
// > /person/1234

Throws a ClientStateException if there is not a value for every token in Resource. (As determined by the existence of any leftover curly braces in the resource after all substitutions have taken place).

Payload : String

Gets or sets the data payload to be sent with this request.

QueryString : String

Returns the concatenated, URI-encoded name/value pairs added via the AddQuery method.

var r = new RESTRequest("/person/search");
r.AddQuery("gender", "male");
r.AddQuery("age", "93");
Console.WriteLine(r.QueryString);
// > gender=male&age=93

Returns null if there are no name/value pairs.

Resource : String

Gets or sets the optionally-tokenized string that represents the path info to the desired resource. When the value is changed, all parameters are cleared (but not the query string).

Timeout : int

Gets or sets the amount of time in milliseconds to wait for a response after sending the request.

Static Properties

GlobalTimeout : int

Gets or sets tee global default to be used by all RESTRequests if no timeout argument is supplied in the constructor.