Page tree
Skip to end of metadata
Go to start of metadata

Overview

RestRequest RestRequest.Expect ( status )

Sets the expected status code to verify request 

Arguments

String status

Status code


Remarks

  • If this method is not used, default expected status codes are used.
  • This method can be called multiple times to allow different status codes.
  • Status Code must be one of the following values from "Status" column;

    StatusCode
    Continue100
    SwitchingProtocols101
    OK200
    Created201
    Accepted202
    NonAuthoritativeInformation203
    NoContent204
    ResetContent205
    PartialContent206
    Ambiguous300
    MultipleChoices300
    Moved301
    MovedPermanently301
    Found302
    Redirect302
    RedirectMethod303
    SeeOther303
    NotModified304
    UseProxy305
    Unused306
    RedirectKeepVerb307
    TemporaryRedirect307
    BadRequest400
    Unauthorized401
    PaymentRequired402
    Forbidden403
    NotFound404
    MethodNotAllowed405
    NotAcceptable406
    ProxyAuthenticationRequired407
    RequestTimeout408
    Conflict409
    Gone410
    LengthRequired411
    PreconditionFailed412
    RequestEntityTooLarge413
    RequestUriTooLong414
    UnsupportedMediaType415
    RequestedRangeNotSatisfiable416
    ExpectationFailed417
    UpgradeRequired426
    InternalServerError500
    NotImplemented501
    BadGateway502
    ServiceUnavailable503
    GatewayTimeout504
    HttpVersionNotSupported505

Examples

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());
Expecting more than one status
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


  • No labels