Skip to content

Instantly share code, notes, and snippets.

@jsmpros
Created September 14, 2022 20:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jsmpros/6519da23d5c3b9d03a8dad7f6a598c9a to your computer and use it in GitHub Desktop.
Save jsmpros/6519da23d5c3b9d03a8dad7f6a598c9a to your computer and use it in GitHub Desktop.
Simple PeopleCode example that invokes a REST GET without metadata
Local Message &resp;
Local Message &req;
Local IBConnectorInfo &connectorInfo;
Local boolean &bRet;
Local string &sJson;
Local string &sUrl;
REM ** IB_GENERIC predates REST. IB_GENERIC_REST is an alternative in later tools releases;
&req = CreateMessage(Message.IB_GENERIC);
REM ** We could load connector properties from a specific node;
&connectorInfo = &req.IBInfo.IBConnectorInfo;
&connectorInfo.ConnectorName = "HTTPTARGET";
&connectorInfo.ConnectorClassName = "HttpTargetConnector";
REM ** To make configurable, move the URL into a URL Definition, message catalog, etc.;
&sUrl = "http://jsonplaceholder.typicode.com/posts/1";
&bRet = &connectorInfo.AddConnectorProperties("Method", "GET", %HttpProperty);
&bRet = &connectorInfo.AddConnectorProperties("URL", &sUrl, %HttpProperty);
REM ** TODO: Add other HTTP headers, such as Authorization header, etc.;
&resp = %IntBroker.ConnectorRequest(&req);
If &resp.ResponseStatus = %IB_Status_Success Then
&sJson = &resp.GetContentString();
REM ** TODO: Parse and process the response;
Else
MessageBox(0, "", 0, 0, &resp.IBException.ToString());
End-If;
REM ** Mock processing to prove it works;
Local File &f = GetFile("c:\temp\posts.json", "W", "U", %FilePath_Absolute);
&f.WriteString(&sJson);
&f.Close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment