The same variable can be used for multiple requests or responses. In the example code below, there's a one variable for requests and one for responses. In the second (and subsequent) calls to the RequestBuilder and the client's Execute(), new objects are created ; the previous value is 'let go' and the AVM's garbage collector evaluates whether it can be cleaned up.
If the DynObjects.Class logging is turned on, the GC at work could be seen, by the Deleted-by-GC entries, similar to the below line:
DYNOBJECTS Deleted-by-GC Progress.Lang.Object Handle:1004
using OpenEdge.Net.HTTP.*.
using Progress.Json.ObjectModel.*.
def var hc as IHttpClient.
def var req as IHttpRequest.
def var resp as IHttpResponse.
// create one isntance of the HTTP client
hc = ClientBuilder:Build():Client.
// each request gets its own IHttpRequest and IHttpResponse objects
// get from server
req = RequestBuilder:Get('http://httpbin.org/get'):Request.
resp = hc:Execute(req).
message
'internal handle: req ' int(req) ' resp: ' int(resp) skip
resp:StatusCode
resp:ContentType
view-as alert-box.
// post to server
req = RequestBuilder:Post('http://httpbin.org/post', new JsonObject()):Request.
resp = hc:Execute(req).
message
'internal handle: req ' int(req) ' resp: ' int(resp) skip
resp:StatusCode
resp:ContentType
view-as alert-box.