RestRequest¶
Represents a single request to a REST service.
Remarks¶
Create a request with RestClient.Request, then add URL, query and form parameters, headers, files or a body. The Add... methods return the request, so calls can be chained.
Execute the request with a method helper such as RestRequest.Get or RestRequest.Post. These helpers check the response status and throw an error for an unexpected status; use RestRequest.Expect to accept other statuses. RestRequest.Execute sends the request with its RestRequest.Method and does not check the status. Methods that end with Async return a Promise.
Examples¶
Send a form with a file¶
1 2 3 4 5 6 | |
Capabilities¶
Request Definition¶
- RestRequest.Method: Gets or sets the HTTP method of the request, such as
Get,Post,Put,PatchorDelete.
Request Parameters and Body¶
- RestRequest.AddFile: Adds a file as a multipart form field.
- RestRequest.AddFileBase64: Adds Base64-encoded content as a multipart form field.
- RestRequest.AddFileBody: Sets the request body to the content of a file.
- RestRequest.AddFileBodyBase64: Sets the request body to Base64-encoded file content.
- RestRequest.AddHeader: Adds an HTTP header to the request.
- RestRequest.AddObject: Sets the request body to an object serialized as JSON.
- RestRequest.AddParameter: Adds a parameter to the request.
- RestRequest.AddQueryParameter: Adds a query string parameter.
- RestRequest.AddUrlParameter: Sets the value of a
{name}placeholder in the resource path. - RestRequest.AddXml: Sets the request body to XML content.
- RestRequest.SetFileFragment: Sets the fragment size for uploading the request body in parts.
Execution¶
- RestRequest.Delete: Performs the request using the DELETE method.
- RestRequest.DeleteAsync: Performs the request asynchronously using the DELETE method.
- RestRequest.Execute: Executes the request with its RestRequest.Method and returns the response.
- RestRequest.ExecuteAsync: Executes the request asynchronously and returns the response.
- RestRequest.ExecuteJson: Executes the request and returns the response body as a JavaScript object.
- RestRequest.ExecuteJsonAsync: Executes the request asynchronously and returns the response body as a JavaScript object.
- RestRequest.ExecuteString: Executes the request and returns the response body as a string.
- RestRequest.ExecuteStringAsync: Executes the request asynchronously and returns the response body as a string.
- RestRequest.ExecuteXml: Executes the request and returns the response body as an XML node.
- RestRequest.ExecuteXmlAsync: Executes the request asynchronously and returns the response body as an XML node.
- RestRequest.Get: Performs the request using the GET method.
- RestRequest.GetAsync: Performs the request asynchronously using the GET method.
- RestRequest.Patch: Performs the request using the PATCH method.
- RestRequest.PatchAsync: Performs the request asynchronously using the PATCH method.
- RestRequest.Post: Performs the request using the POST method.
- RestRequest.PostAsync: Performs the request asynchronously using the POST method.
- RestRequest.Put: Performs the request using the PUT method.
- RestRequest.PutAsync: Performs the request asynchronously using the PUT method.
Request Expectations¶
- RestRequest.Expect: Adds a status code that the response is allowed to have.