**free ctl-opt pgminfo(*pcml:*module:*dclcase) DFTNAME(CLIENTR); // Testing some shit by connecting to beeceptor /COPY /QIBM/ProdData/OS/WebServices/V1/client/include/Axis.rpgleinc DCL-S rc INT(10); DCL-S tHandle POINTER; DCL-S uri CHAR(200); DCL-S response CHAR(32768); DCL-S request CHAR(32768); DCL-S propBuf CHAR(100); DCL-S propBuf2 CHAR(100); // -------------------------------------------------------------------- // Web service logic. The code will attempt to invoke a Web service. // -------------------------------------------------------------------- // Uncomment to enable trace axiscAxisStartTrace('/tmp/luigibrito.log': *NULL); // Create HTTP transport handle. URI has to be set first uri = 'https://methujeraya.free.beeceptor.com/my/api/path' + x'00'; // Transport has to be created once. Recreate when program ends. tHandle = axiscTransportCreate(uri:AXISC_PROTOCOL_HTTP11); if (tHandle = *NULL); PRINT ('TransportCreate() failed'); return; endif; //Do this only when transport is already created and need another request //axiscTransportReset(tHandle:uri); //Reset the transport object to its initial state // testing bee mock rest api PRINT ('testing bee mock rest api'); //As seen below, propbufs are just placeholders. A header is set here propBuf = 'Content-type' + X'00'; propBuf2 = 'application/json' + X'00'; axiscTransportSetProperty(tHandle: AXISC_PROPERTY_HTTP_HEADER: %addr(propBuf):%addr(propBuf2)); //The method is set here. +X'00 is adding a null to the end of the value; propBuf = 'POST' + X'00'; axiscTransportSetProperty(tHandle: AXISC_PROPERTY_HTTP_METHOD: %addr(propBuf)); //It seems the body is set here on the request string. Take note of syntax //of axiscTransportSend. tHandle: %ADDR() //request = '{"studentID":"123456789","firstName":' // + '"New","lastName":"Rec","gender":"Male"}'; request = ''; rc = axiscTransportSend(tHandle: %ADDR(request): %len(%trim(request)): 0); if (rc = -1); checkError ('TransportSend()'); else; flushAndReceiveData(); endif; *inlr = *on; // ========================================= // Print to standard out // ========================================= DCL-PROC PRINT ; dcl-pi *n; msg varchar(5000) const; end-pi; dcl-pr printf extproc(*dclcase); template pointer value options(*string); dummy int(10) value options(*nopass); end-pr; dcl-c NEWLINE CONST(x'15'); printf(%TRIM(msg) + NEWLINE); END-PROC PRINT; // ========================================= // Handle error // ========================================= DCL-PROC checkError ; dcl-pi *n; msg varchar(5000) const; end-pi; DCL-S axisCode INT(10); DCL-S statusCode POINTER; DCL-S rc INT(10); axisCode = axiscTransportGetLastErrorCode(tHandle); PRINT (msg + ' call failed: ' + %CHAR(axisCode) + ':' + %STR(axiscTransportGetLastError(tHandle))); if (axisCode = EXC_TRANSPORT_HTTP_EXCEPTION); rc = axiscTransportGetProperty(tHandle: AXISC_PROPERTY_HTTP_STATUS_CODE: %ADDR(statusCode)); PRINT ('HTTP Status code: ' + %STR(statusCode)); endif; END-PROC checkError; // ========================================= // Flush and Receive data // ========================================= DCL-PROC flushAndReceiveData; dcl-pi *n; end-pi; DCL-S header POINTER; DCL-S property CHAR(100); DCL-S bytesRead INT(10) inz(0); clear response; clear header; // Flush data so request is sent rc = axiscTransportFlush(tHandle); if (rc = -1); checkError ('TransportFlush()'); return; endif; // Receive data and print out data and response to stdout rc = axiscTransportReceive(tHandle: %ADDR(response): %SIZE(response): 0); if (rc = 0); PRINT ('No data to read'); else; dow rc > 0 AND bytesRead < %SIZE(response); bytesRead = bytesRead + rc; rc = axiscTransportReceive(tHandle: %ADDR(response)+bytesRead: %SIZE(response)-bytesRead: 0); enddo; endif; if (rc = -1); checkError ('TransportReceive()'); elseif (bytesRead > 0); PRINT ('Bytes read: ' + %CHAR(bytesRead)); PRINT ('Data: ' + response); endif; if (rc > -1); rc = axiscTransportGetProperty(tHandle: AXISC_PROPERTY_HTTP_STATUS_CODE: %addr(header)); if (rc = -1); checkError ('TransportGetProperty()'); else; PRINT ('HTTP status code: ' + %str(header)); endif; endif; END-PROC flushAndReceiveData;