HTTP and HTTP(S)

Hypertext Transfer Protocol (HTTP) enables client applications to communicate with server applications over the Internet in a standard way. A client application initiates the communication by sending a request message to a Uniform Resource Identifier (URI). The server application processes the request and returns a response message.

Web browsers use HTTP to access websites and end-user web applications. HTTP is also used in programmatic communications, such as REST and SOAP, where client applications send request messages to invoke methods or functions on the server application over the Internet.

HTTP(S) extends HTTP by adding a layer of security (the 'S' in HTTPS stands for Secure). Communication over HTTP(S) happens in a way that is very similar to HTTP; however request and response messages are encrypted before being sent.

To learn more about HTTP and HTTPS, see the following resources:

The OpenEdge.Net procedure library

The OpenEdge.Net procedure library provides classes and interfaces that enable you to make HTTP requests and process HTTP responses from within ABL code. It is included in the PROPATH by default when you create a new OpenEdge project in Progress Developer Studio for OpenEdge. You can also find it in $DLC/tty/netlib (Unix and Windows) and $DLC/gui/netlib (Windows only).

The OpenEdge.Net library supports all HTTP methods and all content types. It also supports HTTP authentication, Transport Layer Security (TLS) communication, the use of HTTP proxies, and the development of stateful HTTP clients using cookies.

Note: The following topics cover the key features of the OpenEdge.Net procedure library. See the OpenEdge API reference documentation to learn about all the available classes, methods, and interfaces. Additional code samples can be found on GitHub.

Main steps

Perform the following steps to develop an ABL HTTP client:

  1. Build an HTTP request
    Use the OpenEdge.Net.HTTP.RequestBuilder class to create a request object that implements the OpenEdge.Net.HTTP.IHttpRequest interface. You must specify an HTTP method (GET, PUT, POST, etc) and a URI. For example:
    DEFINE VARIABLE oURI AS URI NO-UNDO.
    DEFINE VARIABLE oRequest AS IHttpRequest NO-UNDO.
    
    oURI = URI:Parse("http://oemobiledemo.progress.com/OEMobileDemoServices/rest/CustomerService/
    Customer?filter=CustNum=1").
    oRequest = RequestBuilder:GET(oURI):Request.
    You can optionally add HTTP headers and a request body. To learn more about these and other options, see Build an HTTP request.
  2. Execute the HTTP request
    To execute the request, you need a client object and a request object. Use the OpenEdge.Net.HTTP.ClientBuilder class to create a client object that implements the OpenEdge.Net.HTTP.IHttpClient interface. Then, call the Execute() method on the client object. For example:
    DEFINE VARIABLE oClient AS IHttpClient NO-UNDO.
    DEFINE VARIABLE OResponse AS IHttpResponse NO-UNDO.
    
    oClient = ClientBuilder:Build():Client.
    oResponse = oClient:Execute(oRequest).
    You can also use the client object to perform other tasks such as setting cookies or specifying TLS properties. To learn more about these tasks, see Execute an HTTP request.
  3. Process the HTTP response
    Depending on your requirements, you may want to pass the HTTP response to another part of your ABL program, write it to a log file, or use it to query a database. The OpenEdge.Net library supports a wide variety of content types in an HTTP response. To learn more, see Process an HTTP response. In this example, the HTTP response is displayed through the MESSAGE statement.
    IF oResponse:StatusCode <> 200 THEN
        RETURN ERROR "Request Error: " + STRING(oResponse:StatusCode).
    ELSE
        oJsonObject = CAST(oResponse:Entity, JsonObject).
        oJsonObject:Write(JsonString, true).
        MESSAGE string(JsonString).

Example

This example sends a GET request and processes a JSON response:
USING OpenEdge.Net.HTTP.*.
USING OpenEdge.Net.URI.
USING Progress.Json.ObjectModel.*.


DEFINE VARIABLE oClient AS IHttpClient NO-UNDO.
DEFINE VARIABLE oURI AS URI NO-UNDO.
DEFINE VARIABLE oRequest AS IHttpRequest NO-UNDO. 
DEFINE VARIABLE OResponse AS IHttpResponse NO-UNDO.
DEFINE VARIABLE oJsonObject AS JsonObject NO-UNDO.
DEFINE VARIABLE JsonString AS LONGCHAR NO-UNDO.

//Build a request
oURI = URI:Parse("http://oemobiledemo.progress.com/OEMobileDemoServices/rest/
CustomerService/Customer?filter=CustNum=1").
oRequest = RequestBuilder:GET(oURI):Request.

//Execute a request
oClient = ClientBuilder:Build():Client.
oResponse = oClient:Execute(oRequest).

//Process the response
IF oResponse:StatusCode <> 200 THEN
    RETURN ERROR "Request Error: " + STRING(oResponse:StatusCode).
ELSE
    oJsonObject = CAST(oResponse:Entity, JsonObject).
    oJsonObject:Write(JsonString, true).
    MESSAGE string(JsonString). 

Additional resources