Once a request successfully executes (note that success is defined as a successful round trip, however a successful request may return undesired or unexpected results), an IHttpResponse object is returned to the caller. The two most important pieces of data this object returns are the StatusCode and the Entity properties.

The Entity property has a defined type of Progress.Lang.Object although the type of the object contained in it is usually something more specialized. The response will convert text received by an HTTP client into a JsonConstruct, OpenEdge.Core.String or some other type, depending on the ContentType of the response.

The StatusCode property indicates the result of the request. These values can be enumerated by OpenEdge.Net.HTTP.StatusCodeEnum, which is based on https://www.rfc-editor.org/rfc/rfc9110.html#name-status-codes.

Examples

The sample code below retrieves the Entity and writes it to disk in the correct format based on the type of the returned Entity. We can also use the response's ContentType property to perform similar operations.
Note: Before running the code, you should provide a valid username and password for the Credentials and create the temp folder where the output is written.

Extracting typed data from a response

USING Progress.Json.ObjectModel.JsonObject.
USING Progress.Json.ObjectModel.ObjectModelParser.
USING Progress.Lang.Object.
USING OpenEdge.Core.WidgetHandle.
USING OpenEdge.Core.String.
USING OpenEdge.Net.HTTP.IHttpRequest.
USING OpenEdge.Net.HTTP.IHttpResponse.
USING OpenEdge.Net.HTTP.ClientBuilder.
USING OpenEdge.Net.HTTP.RequestBuilder.
USING OpenEdge.Net.HTTP.Credentials.

DEFINE VARIABLE oRequest AS IHttpRequest NO-UNDO.
DEFINE VARIABLE oResponse AS IHttpResponse NO-UNDO.
DEFINE VARIABLE oEntity AS Object NO-UNDO.
DEFINE VARIABLE lcHTML AS LONGCHAR NO-UNDO.
DEFINE VARIABLE hXmlDoc AS HANDLE NO-UNDO.
DEFINE VARIABLE oCredentials as Credentials NO-UNDO. 

oCredentials = NEW Credentials('application', 'admin', 'xxxx'). 
oRequest = RequestBuilder:Get('http://localhost:9090/oem/resources'):~
UsingBasicAuthentication(oCredentials):Request.

oResponse = ClientBuilder:Build():Client:Execute(oRequest).
oEntity = oResponse:Entity.

IF TYPE-OF(oEntity, JsonObject) THEN
    CAST(oEntity, JsonObject):WriteFile('temp/entity.json', true).
ELSE
IF TYPE-OF(oEntity, WidgetHandle) THEN 
DO: 
    hXmlDoc = CAST(oEntity, WidgetHandle):Value. 
    hXmlDoc:save('file', 'temp/entity.xml').
END.
ELSE
DO:
    IF TYPE-OF(oEntity, String) THEN
       lcHTML = CAST(oEntity, String):Value.
    ELSE
       lcHTML = oEntity:ToString().
 
    /* Change extension per the Response's ContentType */
        CASE oResponse:ContentType:
        WHEN 'application/json' THEN
            COPY-LOB lcHTML TO FILE 'temp/entity.json'.
        WHEN 'text/html' THEN
            COPY-LOB lcHTML TO FILE 'temp/entity.html'.
        OTHERWISE
            COPY-LOB lcHTML TO FILE 'temp/entity.txt'.
     END CASE.
END.

The code sample below retrieves the StatusCode of a request and displays it as a message in an alert box.

Status codes

USING OpenEdge.Net.HTTP.IHttpRequest.
USING OpenEdge.Net.HTTP.IHttpResponse.
USING OpenEdge.Net.HTTP.ClientBuilder. 

DEFINE VARIABLE oRequest AS IHttpRequest NO-UNDO.
DEFINE VARIABLE oResponse AS IHttpResponse NO-UNDO.
 
oResponse = ClientBuilder:Build():Client:Execute(oRequest).
MESSAGE
    oResponse:StatusCode SKIP
    oResponse:StatusReason SKIP
VIEW-AS ALERT-BOX.