-
Notifications
You must be signed in to change notification settings - Fork 52
RestRequest
RestRequest
is used to interact with a RestClient
. It defines the pattern for the resource, the request method and the request payload content type.
RestRequest
inherits fromAbstractEventLogger
.
There are multiple constructors that take the following three parameters in various combinations, including no parameters at all.
var r = new RestRequest(HttpMethod.GET, "/resource/{id}", ContentType.TXT);
// could also be written
var r = new RestRequest("/resource/{id}", HttpMethod.GET, ContentType.TXT);
-
HttpMethod
method : The HTTP request method to be used for the request. Defaults toHttpMethod.GET
. -
ContentType
type : The content type of the data being sent. Defaults toContentType.DEFAULT
. -
String
resource : An optionally-tokenized string that represents the path info to the desired resource. Before tokenized requests can be sent, values must be provided for each token. Defaults to an empty string.
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("/{department}/person/{id}");
r.AddParameter("department", "finance");
r.AddParameter("id", "8952-8653345");
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");
var qstr = r.QueryString;
// returns "gender=male&age=93"
-
You do not need to 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
value 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.
r.Reset();
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.
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.
Method : HttpMethod
Gets or sets the HttpMethod
to be used for this request.
Returns the Resource
string with all tokens replaced by their respective values from the AddParameters
method.
Throws a ServerStateException
if there is not a value for every token in Resource
.
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");
var qstr = r.QueryString;
// returns "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).