Expect
Sets the expected status code to verify the request.
| myRestRequest.Expect(status: string):RestRequest
|
Parameters
string status
The status code.
Returns
The current RestRequest instance.
If this method is not used, default expected status codes are used.
This method can be called multiple times to allow different status codes.
The status code must be one of the following values from the Status column:
Example
| var client, request;
client = $Rest.Create(restUrl + '/employers/60ec35c7-7595-4c3a-bb12-f6c8a3be953a/payrun/Year2019/Monthly');
request = client.Request();
request.Method = 'Put';
request.AddHeader('Content-Type', contentType);
request.AddHeader('Authorization', 'Basic ' + authorizationCode);
console.info(request.Expect('Created').Put().ToJson());
|
Allow multiple expected status codes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 | var client, request, response;
client = $Rest.Create(restUrl + '/employers/60ec35c7-7595-4c3a-bb12-f6c8a3be953a/payrun/Year2019/Monthly');
request = client.Request();
request.Method = 'Put';
request.AddHeader('Content-Type', contentType);
request.AddHeader('Authorization', 'Basic ' + authorizationCode);
request.Expect('Created');
request.Expect('BadRequest');
try {
console.info('Calling ' + client.Url);
response = request.Put().ToJson();
if(response.status == 'BadRequest') {
console.error(response.error);
throw response;
}
console.info(response.status);
}
catch (err) {
throw err.error;
}
|
See Also