Skip to content

RestResponse

Represents the response of a REST request.

Remarks

Read the status with RestResponse.StatusCode and the body with RestResponse.Content, or convert the body with RestResponse.ToJson, RestResponse.ToXml or RestResponse.ToBase64. A response returned by RestRequest.Execute is not checked; call RestResponse.Verify to throw an error for an unexpected status.

Examples

Handle a missing resource

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
var response = $Rest.Create('https://api.example.com/')
    .Request('customers/{id}')
    .AddUrlParameter('id', $Xml.Evaluate('Customer/Id'))
    .Execute();

if (response.StatusCode === 'NotFound') {
    $Xml.SetValue('Customer/Exists', false);
} else {
    response.Verify();
    $Xml.SetValue('Customer/Name', response.ToJson()['name']);
}

Capabilities

Response Metadata

Response Validation

Response Conversion