-
Notifications
You must be signed in to change notification settings - Fork 50
RestRequest
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.
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.
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.
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.
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.
Gets or sets the ContentType
to be used for this request.
Encoding : Encoding
Gets or sets the Encoding
to be used for this request.
Headers : WebHeaderCollection
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.
Gets or sets the HttpMethod
to be used for this request.
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).
Gets or sets the data payload to be sent with this request.
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.
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).
Gets or sets the amount of time in milliseconds to wait for a response after sending the request.
Gets or sets tee global default to be used by all RESTRequests
if no timeout
argument is supplied in the constructor.