[Progress Communities] [Progress OpenEdge ABL] Forum Post: RE: Calling REST API from Progress Client

Status
Not open for further replies.
T

Torben

Guest
After importing certificates I get the following code to give desired result. Think they are behind load balancer, so you need the ServerNameIndicator BLOCK-LEVEL ON ERROR UNDO, THROW. USING OpenEdge.Core.*. USING OpenEdge.Net.HTTP.ClientBuilder. USING OpenEdge.Net.HTTP.IHttpRequest. USING OpenEdge.Net.HTTP.IHttpResponse. USING OpenEdge.Net.HTTP.RequestBuilder. USING OpenEdge.Net.HTTP.Lib.ClientLibraryBuilder. DEFINE VARIABLE jOut AS Progress.Json.ObjectModel.JsonArray NO-UNDO. FUNCTION InvokeworldBank RETURNS Progress.Json.ObjectModel.JsonArray (): DEFINE VARIABLE oHttpRequest AS IHttpRequest NO-UNDO. DEFINE VARIABLE oHttpResponse AS IHttpResponse NO-UNDO. DEFINE VARIABLE oUri AS OpenEdge.Net.URI NO-UNDO. DEFINE VARIABLE oLib AS OpenEdge.Net.HTTP.IHttpClientLibrary NO-UNDO. // Set server to call oUri = (NEW OpenEdge.Net.URI('https', 'api.worldbank.org')). oUri:path = '/countries'. oUri:addQuery("format", "json":U). // Set ssl properties oLib = OpenEdge.Net.HTTP.Lib.ClientLibraryBuilder:Build() // :SslVerifyHost(FALSE) :ServerNameIndicator('api.worldbank.org') :library. oHttpRequest = OpenEdge.Net.HTTP.RequestBuilder:Get(oUri):Request. // Call and get response oHttpResponse = ClientBuilder:Build() :UsingLibrary(oLib) :Client:Execute(oHttpRequest). MESSAGE oHttpResponse:StatusCode SKIP oHttpResponse:StatusReason VIEW-AS ALERT-BOX INFORMATION. IF TYPE-OF(oHttpResponse:Entity, Progress.Json.ObjectModel.JsonArray) THEN RETURN CAST(oHttpResponse:Entity, Progress.Json.ObjectModel.JsonArray). UNDO, THROW NEW Progress.Lang.AppError("Wrong response type", 0). END FUNCTION. // Call worldBank with input parameters jOut = InvokeworldBank(). // Message 200 first chars of result MESSAGE STRING(SUBSTRING(jOut:GetJsonText(), 1, 200)) VIEW-AS ALERT-BOX INFORMATION. [{"page":1,"pages":7,"per_page":"50","total":304},[{"id":"ABW","iso2Code":"AW","name":"Aruba","region":{"id":"LCN","value":"Latin America & Caribbean "},"adminregion":{"id":"","value":""},"incomeLevel

Continue reading...
 
Status
Not open for further replies.
Top